Answering your question, not the syntax you used is not valid Binary Logic Operators are normally used with boolean values and return a boolean.
In your first condition for example:
if(valor>1&&9) {...
If you want to compare valor
is between 1 and 10 should be made so:
if(valor > 1 && valor < 10) {...
For the logical conjunction operator &&
will:
- Testing the first sentence
valor > 1
...
- ...if the value of the judgment is
true
he goes on to the next test...
- ...if the value of the judgment is
false
it stops the test and returns false.
- Test the sentence
valor < 10
..
- ...if the value of the judgment is
true
returns true
.
- ...if the value of the judgment is
false
returns false
.
Or simply the conjunction operator &&
tests two boolean sentences and returns true only if both sentences are true.
An addendum with three ways to make these comparisons:
With the statement if...
do {
var n = parseInt(window.prompt("Digite um número:"));
} while (isNaN(n));
if (n < 0){
alert("Negativos não valem!");
} else if (n == 0) {
alert("Zero!");
} else if (n < 10){
alert("Muito pouco!");
} else if (n < 15){
alert("Bom!");
} else if (n < 20){
alert("Muito bom!");
} else {
alert("Passou...");
}
With the statement switch/case
do {
var n = parseInt(window.prompt("Digite um número:"));
} while (isNaN(n));
switch (true) {
case n < 0:
alert("Negativos não valem!")
break;
case n == 0:
alert("Zero!")
break;
case n < 10:
alert("Muito pouco!")
break;
case n < 15:
alert("Bom!")
break;
case n < 20:
alert("Muito bom!")
break;
default:
alert("Passou......")
}
With the conditional ternary operator
do {
var n = parseInt(window.prompt("Digite um número:"));
} while (isNaN(n));
alert(
(n < 0) ? "Negativos não valem!" :
(n == 0) ? "Zero" :
(n < 10) ? "Muito pouco!" :
(n < 15) ? "Bom!" :
(n < 20) ? "Muito bom!" :
"Passou......"
);
Is that Javascript? Anyway, if it’s to test if the number is between 1 and 10, it would be
if (valor >= 1 && valor <= 10) { alert("muito pouco") }
- already to have several conditions chained, iselse if
and notif else
, something like this: https://ideone.com/tl0gye - not to sound boring or anything, but as it seems that you are "getting" the basic syntax of the language, I suggest you go back to the basics and start from here - seriously, it’s not irony or anything, it’s a genuine attempt to help...– hkotsubo
Yes, I’m picking up because I started a little while ago ahaha.. Thanks for your help! ^^
– Daniel R. R