-1
Good staff I am beginner in the area of web and Javascript. My teacher asked me to prepare a simple Calculator with the four operations (+), (-), (*), (/). Only with pure Javascript to run on the terminal, no HTML code or other. Then I saw that there is a need to create the questions about which operation the user wants to perform, as well as enter the first and the second number. I used IF/Else, I was able to run the code, but when showing the result it returns Nan. Could someone help? That is the code:
var valor
var valor1
var oper
var readlineSync = require('readline-sync');
oper = parseFloat(readlineSync.question("Qual operacao deseja efetuar (+) (-) (*) (/)? : \n"));
valor = parseFloat(readlineSync.question("Insira o primeiro numero: \n"));
valor1 = parseFloat(readlineSync.question("Insira o segundo numero: \n"));
if (oper =="+") {
return valor + valor1;
} else if
(oper == "-") {
return valor - valor1;
} else if
(oper == "*") {
return valor * valor1;
} else if
(oper == "/") {
return valor / valor1;
} else {
console.log('Não foi possível calcular')
}
console.log('O resultado é', +oper)
Ronde, you are wearing
parseFloat
to receive the value inoper
.– GeekSilva