Functions and if/else


var sleepCheck = function (numHours){;

    if (numHours >= 8){;
        return "You're getting plenty of sleep! Maybe even too much!"};
    else {;
        return "Get some more shut eye"};


//Please check for errors


When are semicolons used in JavaScript? It seems you have one at the end of every line of code. This is going to create syntax errors that prevent code execution.


Thank you for the help!


Remember to use curly braces/brackets { } when you want to encapsulate a code block. With a function, your format will go something like:

var functionName = function(parameter) {
code code code ;


var sleepCheck = function (numHours){

if (numHours >= 8){
    return "You're getting plenty of sleep! Maybe even too much!"}
else {
    return "Get some more shut eye"}



//Please check for errors

Not working with sleepCheck(5)


There are some good posts on the forums that give tips on syntax guidelines. Here's one for semicolons that you might find useful:

I think you'll get a feel for where and when to use them as you progress. Also, you can use sites like or to practice code on and to see the whys behind error messages you come across.


Some statements end with a semi-colon, I would look up the syntax for the statement I'm wondering about.

For example:

Is missing a semi-colon, because assignment statements end with semicolon! It should look like:

var functionName = function(parameter) {

A function statement on the other hand, does not end with a semi-colon:

function functionName(parameter) {


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