0
var A, B, C;
A=prompt("Digite um valor.");
B=prompt("Digite um valor.");
C=prompt("Digite um valor.");
console.log("TRIANGULO: "+(A*C)/2);
console.log("CIRCULO: "+(3.14159*C*C));
console.log("TRAPEZIO: "+(A+B)*C/2);
console.log("QUADRADO: "+(B*B));
console.log("RETANGULO: "+(A*B));
In console.log("TRAPEZIO: "+(A+B)*C/2);
the result is 34
and I don’t understand why.
Prompt returns string, so A+B concatenates instead of adding. Use
Number(A) + Number(B)
to solve.– Guilherme Nascimento
Thank you, I tried using promptNumber but could not. I had faced this problem before.
– Márcio
There is no
promptNumber
... do so:A=Number(prompt("Digite um valor."));
and then on the console.log isolate the string’s mathematical operation with parentheses:console.log("TRAPEZIO: " + ((A+B)*C/2) );
– Guilherme Nascimento