Help! My code is not working and I don't know why!

Hey, @Grasshopper_Ben. My code is working fine, however, when the if statement detected the ‘x’ letter, it do not return false. What is wrong with this code. I rechecked a lots of times. Please answer.

This code will never output “false” because “letter” will never be “x” as you do not have “x” in the text array. In the code above, letter is equal to “export”. Yes, there is the letter “x” in it but your code is checking if “letter” is equal to “x” not if the letter “x” is detected.

Another thing, after you return something in a function, the function is finished. So the console.log you wrote after the “return true” will never get executed.

Lmao, how to fix it?

  • Pummarin

I dunno, but I think you can use .contains() method

What about those console.log() I writen below those return statements?

I’ve one one solution:

Just apply it to your code… The return statement will not prevent the “console.log(5)” to execute.

Here there is no “3” logged to the console because the “return false” has stopped the function. So the console.log is never executed.

Hey there, your function isn’t checking if a word contains the letter 'x'. It’s checking if a word is equal to 'x'. Try using the .includes() method to check if a string contains a specific character.

Also, when the function hits a return statement, it immediately stops running and returns a value. Any code placed below a return statement will never run. Try moving your console.log() statements up a line so they are before the return statements.

Hope this helps!

1 Like

Thank you @Grasshopper_Ben. I didn’t know that I’m an idiot when creating this program. :joy:

I didn’t know about the difference between the !== comparison operator and the .includes() method. (Ben - 1, Doge - 0)

Next, the return statement, I’m really don’t know how to use the return statement, so I don’t understand it. (Ben - 2, Doge - 0)