DHTML_XML2_14

<!DOCTYPE html> <html> <head> <title>Unit 2 - Q14</title> <script type="text/javascript"> var choice; document.write("<br>--- Calculator ---<br>"); document.write("1. Add<br>2. Subtract<br>3. Multiply<br>4. Divide<br><br>"); function calc() { var x=Number(prompt("Enter no. 1")); var y=Number(prompt("Enter no. 2")); choice=prompt("Enter operation"); if(choice==1) document.write("Sum = ",(x+y)); else if(choice==2) document.write("Subtraction = ",(x-y)); else if(choice==3) document.write("Product = ",(x*y)); else if(choice==4) document.write("Quotient = ",(x/y)); else alert("Wrong Input!"); } </script> </head> <body> Click the button below to enter 2 numbers and choose an operation.<br> <input type="button" value="Enter" name="b1" onclick="calc()"> </body> </html>

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.