19 help


#1

("Jon".length * 2 / (2+1) === 2 )
if
{
console.log("The answer makes sense!");
}
else
{
console.log("Error Error Error");
}

why does this not work?


#2

these two lines

("Jon".length * 2 / (2+1) === 2 )
if

should rather be

if("Jon".length * 2 / (2+1) === 2 )

Remember this is the correct syntax for if/else

if(condition){
    //statements
}
else{
    //statements
}

#3

thanks for help didnt see the missing number after ===


#4

Hello Rydan,

Thank you very much for your help. I don't understand one thing though if you might explain this it would be helpful. When I wrote my code I had problems with the first string I had written:
follow
if ("Jon". length 2 / (2+1 ) === ). I don't understand why in the code "2" follows after the "===" ??????


#5

i got this syntax error of ';'


#6

if ("Jon".length * 2 / (2+1) === 2 )
{
console.log("The answer makes sense!");
}
else
{
console.log("This answer is true and makes sense!");
}

This is what i wrote and I finally got it right! It was a little tricky for me at first! I hope this can help you in some way!


#7

@bobcat11 first things is there is an error in the code block. it should be

if (("Jon". length *2) / (2+1 ) === 2 )

lets break it down

("Jon". length *2) / (2+1 )

so the length of "Jon" will be 3 i.e

"Jon". length  -----> 3

So now lets put that in the the expression above

(3*2)/(2+1)

//now we have
(6)/(3)   //==>2

so now you know that the expression above will evaluate to 2
and that's what the if block is checking
hence

if (("Jon". length *2) / (2+1 ) === 2 )
//will be the same as saying
if(2 === 2) // which is true

Hope this helped?


#8

thank you @jessica_davis17 for the hint :smile:


#9

your welcome! Im glad it could help!


#10

A post was split to a new topic: I don't get it!


#11

Great! Awesome. Very easy to understand.

Thank you! #URtheBEST


#12

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