Skip to content

Instantly share code, notes, and snippets.

@Julisam
Created June 24, 2022 13:56
Show Gist options
  • Save Julisam/0559bb033d5dbaa4e39e2b6d1fe4ce34 to your computer and use it in GitHub Desktop.
Save Julisam/0559bb033d5dbaa4e39e2b6d1fe4ce34 to your computer and use it in GitHub Desktop.
Introduction to JavaScript
// 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