If(10 % 2 === 0 "true" );


#1

if(10 % 2 === 0 "true" );
{
console.log("The first number is even")
}
else(14 % 6 === 0 "false");
{
console.log("The first number is odd")
}


Me need help
#2

i think you don't need to write "true" in your first statement, just
fi(10%2===0);
{
console log.... etc


#3

if(10 % 2 === 0 "true" );
{
console.log("The first number is even")
}
else(14 % 6 === 0 "false" );
{
console.log("The first number is odd")
}


#4

Take out the "true" and "false" in your if loops.


#5

ok thanks i was really stuck


#6

Also no conditions after else.


#7

Right,

else {...}

is a broad statement that encompasses all other possible outcomes send to the if statement.

You could make it an else if statement (see below) and that will allow you to keep your parameter.

else if(14 % 6 === 0) {...}
      ^

One more correction.

if(10 % 2 === 0);
                ^

and

 else(14 % 6 === 0);
                   ^

the semi-colon, or ";" is used to tell the computer "Hey stop here, I'm done with this statement."
That means when you put it at the end of an if statement it will not run any of the code in the if statement and the computer will look at you with a sad smile and just shake its head in disappointment.


#8

:smile: :smile: :smile:

Unfortunately this end-of-statement ability of the semicolon will lead to the execution of the code in {} after the if which makes the if either useless or even dangerous when an else is following. Wrote a longer post over here:


#9

Right right, sorry I am thinking back to my C++/C# days. I'm mixing up languages left and right x.x


#10

No problem the direction was still ok. But isn't it pretty much the same in the C family?


#11

Similar, however I believe that once you hit the ";" in an if statement it'll just error. I could be wrong, that was back in high school.


#12

your code should be like this :blush:

if(10 % 2 === 0)
{
console.log("The first number is even")
} else {

console.log("The first number is odd")

}

know that its right.


#13

I've tried many true statements but won't work. so just took it from the example
if(16 % 2 === 0)
{
console.log("The first number is even");
} else {
console.log("The first number is odd");
}
but still giving me an error. why?