Here is a sample program that demonstrate how to use JavaScript to perform basic math operations. The code is very easy to understand for beginners in JavaScript programming.
If you have some questions please send me an email at jake.r.pomperada@gmail.com and jakerpomperada@yahoo.com. My mobile number here in the Philippines is 09173084360.
Sample Program Output
Program Listing
<head>
<title>Basic Math in JavaScript </title>
</head>
<style>
h3 {
font-family:arial;
};
</style>
<body>
<script>
var num1 = parseInt(prompt("Enter first vallue : "));
var num2 = parseInt(prompt("Enter second vallue : "));
var sum = (num1 + num2);
var difference = (num1 - num2);
var product = (num1 * num2);
var quotient = (num1 / num2);
document.write("<br>");
document.write("<h3> Basic Math in JavaScript </h3>");
document.write("<font face='arial' size='3'> The sum of ");
document.write(+ num1 + " and " + num2 + " is " + sum + ".</font><br>");
document.write("<font face='arial' size='3'> The difference of ");
document.write(+ num1 + " and " + num2 + " is " + difference + ".</font><br>");
document.write("<font face='arial' size='3'> The product of ");
document.write(+ num1 + " and " + num2 + " is " + product + ".</font><br>");
document.write("<font face='arial' size='3'> The quotient of ");
document.write(+ num1 + " and " + num2 + " is " + quotient + ".</font><br>");
document.write("<h3> End of Program </h3>");
</script>
</body>
</html>
No comments:
Post a Comment