Else ... if coding help

Hi forums!

I’m just starting out on the full-stack path.

I need help figuring out why this practice if…else code I wrote isn’t working, to me it looks identical to the lesson code. What am I missing here?

Thanks for any help!

Hello,

Be mindful that = and == / === are very different. You are assigning the value ‘7am’ to myAlarmClock instead of comparing the values here: if (myAlarmClock = '7am')

Here’s a handy cheatsheet from Codecademy about JavaScript Conditionals: Conditionals. The Comparison Operators section has good examples.

3 Likes

In addition to what @selectall has pointed out, you have an issue here:

Code in an else block is what we want to execute if none of the conditions are met. We can’t have a condition attached to else.

4 Likes

Thank you, I got the programme to run! That was an important distinction in how I understand the use of else vs. else if :slight_smile:

1 Like

Thanks for clarifying this, it was very helpful and the programme runs as intended now!

1 Like