The problem is that prompt()
returns a string .
This is not noticeable in multiplication because JavaScript tries to convert to numbers but when you start this concatenation with a string, the conversion is left to right and everything is string .
Test typeof cFabrica
and you will see that it gives string
.
The solution is to convert numbers so there are no doubts / bugs.
var cFabrica = prompt("Insira o valor de fabrica do veículo");
// teste 1
console.log('cFabrica é do tipo:', typeof cFabrica);
var numerocFabrica = Number(cFabrica);
// teste 2
console.log('numerocFabrica é do tipo:', typeof numerocFabrica);
var comissao = 0.28 * cFabrica;
var imposto = 0.45 * cFabrica;
var cFinal = numerocFabrica + comissao + imposto;
console.log("O valor final é: ", cFinal);