In this article I would like to show you how to create a prompt JavaScript calculator. Our program is very simple it will ask the user to give the first value, the second is the operator addition, subtraction, multiplication and division and then the second value. Our program will display the result on the screen using if else statement in JavaScript.
I am currently accepting programming work, it project, school
programming projects , thesis and capstone projects, IT consulting
work, computer tutorials and web development work kindly contact me in the following email address for further details. If you want to advertise in my website kindly contact me also in my email address also. Thank you.
My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.
My mobile number here in the Philippines is 09173084360.
My telephone number at home here in Bacolod City, Negros Occidental Philippines is +63 (034) 4335675.
Sample Program Output
Program Listing
index.htm
<html>
<head>
<title> JavaScript Calculator </title>
</head>
<style>
body {
font-family:arial;
background-color:lightgreen;
font-size:24px;
font-weight:bold;
}
</style>
<body>
<script>
var a = parseInt(prompt("Give first value"));
var opt= prompt("Give operator");
var b = parseInt(prompt("Give second value"));
if (opt =='+') {
add = (a+b);
document.write("The sum of " + a + " and "
+ b + " is " + add + ".");
}
else if (opt =='-') {
sub = (a-b);
document.write("The difference of " + a + " and "
+ b + " is " + sub + ".");
}
else if (opt =='*') {
mul = (a*b);
document.write("The product of " + a + " and "
+ b + " is " + mul + ".");
}
else if (opt =='/') {
div = (a/b);
document.write("The quotient of " + a + " and "
+ b + " is " + div + ".");
}
else {
document.write("Invalid Operation !!!");
}
</script>
</body>
</html>
No comments:
Post a Comment