prompt()
function returns the result as a string, and not as a number. So you must convert each to integer using parseInt(number)
. If you don’t do that, both your operator and the numbers are strings.
do {
var calculChoice = parseInt(prompt("What do you want to do ?\n\n 1 - Addition\n 2 - Soustraction\n 3 - Multiplication\n 4 - Division"));
} while(calculChoice != 1 && calculChoice != 2 && calculChoice != 3 && calculChoice != 4);
console.log(calculChoice);
do {
var premierNombre = parseInt(prompt("entrez votre premier nombre"));
var deuxiemeNombre = parseInt(prompt("entrez votre second nombre"));
} while (isNaN(premierNombre)||isNaN(deuxiemeNombre));
CLICK HERE to find out more related problems solutions.