Lesson 21 on javascript


#1

Im stuck, here is my answear, i dont get why is false..
thx for helping me ! :slightly_smiling:
if (console.log (10 % 2===0))
{
console.log("The first number is even");
}
else
{
console.log("The first number is odd");
}


#2

i think that your code should be like that

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

#3

The result of calling console.log() is always undefined and undefined is interpreted as false. You can test it like this:

console.log(console.log(5));

will result in:

5
=> 'undefined'

So what you have there is:

if (undefined) {...

#4

Thanks @wizmarco I was getting an error because I was putting it in as - if (console.log (10 % 2 === 0)


#5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.