To run this, put it in a .txt file and then rename it .html and open it.
Source code:
Here is the same thing, but this one uses functions to do the math:Code:<script type = "text/javascript"> <!-- TheEliteOne's JavaScript Calculator Example > var num1 = prompt("Enter number one: "); var num2 = prompt("Enter number two: "); document.write(num1 + num2 + "<br>"); document.write(num1 - num2 + "<br>"); document.write(num1 * num2 + "<br>"); document.write(num1 / num2 + "." + num1 % num2); </script>
:)Code:<script type = "text/javascript"> function add(a,b) { return a + b; } function sub(a,b) { return a - b; } function mult(a,b) { return a * b; } function div(a,b) { return a / b; } function div2(a,b) { <!-- This is to get the remainder > return a % b; } var num1 = prompt ("Enter number one: "); var num2 = prompt ("Enter number two: "); document.write(add(num1,num2) + "<br>"); document.write(sub(num1,num2) + "<br>"); document.write(mult(num1,num2) + "<br>"); document.write(div(num1,num2) + "." + div2(num1,num2)); </script>






Reply With Quote
Bookmarks