-2
I’m still starting to learn JS, so I just want you to explain to me and give me example.
-2
I’m still starting to learn JS, so I just want you to explain to me and give me example.
1
function verificaNegativo(valor) {
if (valor < 0) {
alert("O numero é negativo");
} else {
alert("O numero é Positivo");
}
}
You can use a simple function that checks if the number passed is less than 0.
1
The concept of negative number is to be less than zero.
In programming, there are "conditional tests", which perform an action if true.
In JS and most languages, it is done within a structure if
and else
.
You can do it in your code like this:
if(numero < 0)
It is worth remembering that numero
is a variable, and must be defined in advance.
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
Very good, sounds silly, but there are times when it turns white.
– adventistapr