-4
Why are you repeating the number instead of adding?
var valor = prompt("calculo")
var valor1 = prompt("adição")
if (valor + 0 || valor1 + 0) {
document.write(valor += valor1)
} else {
document.write("valor incorreto")
}
-4
Why are you repeating the number instead of adding?
var valor = prompt("calculo")
var valor1 = prompt("adição")
if (valor + 0 || valor1 + 0) {
document.write(valor += valor1)
} else {
document.write("valor incorreto")
}
0
Every return of the prompt is a string, in which case you are adding 2 string, where concatenation will occur.
You can use parseint() to fix the problem.
var valor = parseInt(prompt("calculo"))
var valor1 = parseInt(prompt("adição"))
if (valor + 0 || valor1 + 0) {
document.write(valor += valor1)
} else {
document.write("valor incorreto")
}
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
There is no need to answer a question that is duplicated, as I mentioned in my comment. If you think you can make an answer that adds value to the community, do it at related question. However, your answer does not differ from the existing.
– Rafael Tavares