I'm truly stuck on lesson 19


#1

Hello all. I'm truly stuck on lesson 19. I used the codes above but it isn't working. Help. See my code below:

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


EXERCISE19 math
#2

Please post a link to this exercise so we can see what the instructions are asking for :slight_smile:


#3

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

You forgot to insert a parenthetical citation before "Jon" on line one. This should be the right code.


#4

Thanks pannef I added the parentheses. It still isn't working.

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


#5

Check my comment by the line in your code above.


#7

@mstheodora You should place console.log("The answer makes sense!"); between the brackets like this
{
console.log("The answer makes sense!");
}
and delete your first line with ("Jon".length * 2 / (2+1) === ) because you have it twice and only needed once with if

I hope this helped mstheodora! Good luck :wink:


#8

Thanks so much jornemoonren, I got it to work last week by doing just what you said.. But any help you can provide in the future would be great. I was confused because they said not to Thanks. This is what I did:

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


#9

These are the instructions we have to follow :
1. Complete the missing bits of code to construct the if / else statement. Make the condition evaluate to true.
2. Finish the else statement by printing out the string "Error Error Error" to the console.

This is what i code

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

This is what my console is showing :- The answer makes sense!

my code ran successfully, but i haven't printed out the string "Error Error Error" from the else statement. Is this a bug? How can someone satisfies the if condition and then executes the else statement.

Is there actually some problem with the question or have i misunderstood the question?


#10

This what I was told to do and it worked. I think there may be a bug because I don't know why this below worked but it did.

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


#11

You had forgot the opening parenthesis after the if.


#12

@mstheodora, look to your condition:

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

How do you think, what does it mean? Literally it means if(2 + 1/2*3) or if(3.5). Does it make sense?

From MDN:

The if statement executes a statement if a specified condition is true. If the condition is false, another statement can be executed.

Your condition always return true and else has no sense.
Should be like this:

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

I think, that if--else statement is used to perfom different actions based on different conditions. When you add comparsion operator you can get true or false and perform action you want based on result of the condition:

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

result: "Error Error Error"


#13