1
I want to write an algorithm, in JAVASCRIPT, that reads an N number and makes the sum only of even numbers
var n1, n2, n3, soma;
n1 = parseInt(prompt("Digite o 1º Número :"));
n2 = parseInt(prompt("Digite o 2º Número :"));
n3 = parseInt(prompt("Digite o 1º Número :"));
document.write("Seus Números Digitados foram: " + n1 + " , " + n2 + " , " + n3 + "<br>");
if ((n1 % 2 && n2 % 2) == 0) {
if ((n3 % 2) == 0) {
soma = n1 + n2 + n3;
document.write("Resultado é: " + soma);
}
} else if ((n2 % 2 && n3 % 2) == 0) {
soma = n2 + n3;
document.write("Resultado é: " + soma);
} else if ((n3 % 2) == 0) {
soma = n3;
document.write("Resultado é: " + soma);
} else {
document.write("ERRO");
}
}
Charlie, this is a question or an answer?
– Sergio
@Sergio If it’s an answer, with the
if ((n1 % 2 && n2 % 2) == 0)
, i doubt it would be the right answer. That must be the code he tried.– Victor Stafusa
@Victorstafusa, too, I think, but I wasn’t 100% sure
– Sergio
I’m sorry - me the lack of clarity, I’m new on the site and I still haven’t caught the ruse of how to use it properly, so, I thank everyone who answered I’ll try here... that code I sent there was the one I tried, but I couldn’t with it. Then I sought help here, so that someone who knows, help me. (I am very new to this, I started to learn about it recently)
– Charlie Custer