Functions recap if/else. Cant see what is wrong


#1

Can someone please explain where I am going wrong.

Thanks
Carol


#2

You're not printing it so no need to console.log. Simple use sleepCheck() with the number of hours inside the bracket. If you were however, using console.log, you would need an additional closing bracket for each line of code :slightly_smiling: Hope that helps @caroldavies!


#3

¥eah I had the additional bracket still wasnt working. I will try removing the console.log. Thanks


#4

removing the console.log has helped still not working. Error says it something to do with the else. I have refreshed logged out and logged back in. it still is not working. I am using firefox.


#5

Ah wait, I realised what else is wrong. You haven't open braced you 'if' statement. You've used a semicolon instead.

So you should open for the function, open for the if statement, and open for the else statement (and of course close all three).


#6

i have removed the semicolon but there is an { after (numHours)


#7

Need 2 sets of { for some reason


#8

Yep. So that brace after (numHours) is for your function right?

Then for your if statement, you need to open a new brace which closes after the first return statement. Then you open one for else { which closes after the return statement. And then you have the closing brace for the function. Does that make sense?


#9

Sorry, late reply - I guess you worked it out. But in answer to your question around two sets - take a step back and think about it this way. For which lines of code do you need braces?

FUNC { }
IF { }
ELSE { }

So in your structure it would be

FUNC { IF { ELSE { } } }

Get it?


#10

The console.logs are fine and I'd actually recommend to keep the. If you omit the semicolons at the end you only see one "pseudo output" meaning the console just repeats the last value used in the code. With console.logs you'd see all three function calls correctly displayed. But you're correct about the missing ) at the end.

And about the semicolon you may have a look at this longer explanation here:


#11

Hi, i need help about this , I can`t find any problems with my cintax


#12

The syntax seems to be ok, I'd go for typos in the output message. Just copy and paste them.


#13

That`s what i tought , but i all ready try that, and still not working...:slightly_smiling:


#14

suddenly it`s working...