Verified Commit 4acb7845 authored by Eric Zhu's avatar Eric Zhu 🎒

added the js and html file

Signed-off-by: Eric Zhu's avatarEric Zhu <eric@korzq.xyz>
parent 80e32c67
<html>
<head>
<title>JS Calculator</title>
</head>
<body>
<h1> A Javascript Calculator</h1>
<input type="button" value="Refresh Page" onClick="window.location.reload()">
</body>
<script src="calculator.js"></script>
</html>
<!-- Happy hacking! -->
\ No newline at end of file
// JS Calculator
// Ask user for the operation
var operation = prompt("Hello! Welcome to Eric's calculator!\n To do addition, enter 1.\n To do subtraction, enter 2.\n To do multiplication, enter 3.\n To do division, enter 4.");
// If user did not enter anything
if(operation == null){
alert("Sorry, please try again.")
}
// addition
else if(operation == 1){
var number1 = prompt("Please enter the first number");
var number2 = prompt("Please enter the second number");
alert ("The sum is " + (Number(number1)+Number(number2)));
}
// subtraction
else if(operation == 2){
var number1 = prompt("Please enter the first number");
var number2 = prompt("Please enter the second number");
alert ("The difference is " + (Number(number1)-Number(number2)));
}
// multiplication
else if(operation == 3){
var number1 = prompt("Please enter the first number");
var number2 = prompt("Please enter the second number");
alert ("The product is " + (Number(number1)*Number(number2)));
}
// division
else if(operation == 4){
var number1 = prompt("Please enter the first number");
var number2 = prompt("Please enter the second number");
alert ("The quotient is " + (Number(number1)/Number(number2)));
}
// Happy hacking!
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment