Using the basis that the colleagues above sent I have put together something a little more descriptive, maybe it will be useful for you in this beginning.
To help I will try to explain in a simple way the about 2 logical operators that are most used in the beginning the ||
and the &&
.
The ||
is a logical operator that translated means 'OR', or in English 'OR'. It is used when at least one of its conditions is true.
The &&
is a logical operator that translated means 'AND', or in English 'E'. It is used when all its conditions are true.
In his case it was used the && therefore it was necessary that the tested value was bigger than all the others at the same time.
I hope I helped. I’ll leave one link that can be useful too.
//Declaração das variáveis.
var valor1 = 3;
var valor2 = 9;
var valor3 = 1;
//Condições para encontrar o maior valor.
//Caso o valor1 seja maior que o valor2 E valor1 seja maior que valor3 (O valor1 é o maior).
if (valor1 > valor2 && valor1 > valor3) {
console.log("O valor 1 é o maior")
}
//Caso o valor2 seja maior que o valor1 E valor2 seja maior que valor3 (O valor2 é o maior).
else if (valor2 > valor1 && valor2 > valor3) {
console.log("O Valor 2 é o maior")
}
//Caso não seja o valor1 nem o valor2, então quer dizer que o valor3 é o maior.
else {
console.log("O valor 3 é o maior")
};
You know logic operators ? take a look at the documentation https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operadores_Logicos
– Joan Marcos
i don’t know anyone, but in this example I quoted above, so I won’t use if?
– Miyuki Fukagawa
It is not possible to know the purpose of the code, but normally, in situations like this, you will not use an algorithm that simply compares pre-initialized values, because in practice it would not make sense. The best way to make the code more usable is to create a higher variableValor, start it with zero (in case it contains only positive numbers) and perform the comparisons. At the end, just print the highest variable.
– Rodrigo Rossi
is that are exercises to learn how to work javascript, mass brigadea
– Miyuki Fukagawa