Created
June 24, 2022 13:56
-
-
Save Julisam/0559bb033d5dbaa4e39e2b6d1fe4ce34 to your computer and use it in GitHub Desktop.
Introduction to JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// basic arithmetic calculator without a frontend | |
var operations = ["+", "-", "*", "/", "**", "%"] | |
let operation = prompt("Please enter operation"); | |
// check if operation is valid | |
while (true){ | |
if (!(operations.includes(operation))){ | |
operation = prompt("Invalid operation: Enter operation again") | |
} | |
else { | |
break; | |
} | |
} | |
let number1 = prompt("Good\nEnter first number"); | |
operation = number1 + " " + operation | |
let number2 = prompt(operation, ""); | |
operation += " " + number2 | |
// print result | |
alert(operation + " =\n" +eval(operation)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment