8/14 Making a calculator


#1

Hey.

I've decided to make a simple calculator.

// Write your code below!

var num1 = prompt("enter first number");
var oper = prompt("enter action (+, -, *, /)");
var num2 = prompt("enter second number");

switch (oper) {
case "+":
console.log(parseFloat(num1) + parseFloat(num2));
break;
case "-":
console.log(num1 - num2);
break;
case "*":
console.log(num1 * num2);
break;
case "/":
console.log(num1 / num2);
break;
default:
oper;
};

Still cannot set default action. What if I enter something else than math operation?
Can i do something here considering my current knowledges?


#2

Just replace oper in the default case with e.g.

console.log("Sorry, this is not a correct math operator. Please try one of those +,-,* or /.")

or what do you mean?


#3

I want this:
if i enter incorrect symbol on step two then i start over


#4

Wrap it in a while loop and only leave it if the statement is one of those 4.