Lesson 12 Functions & if/else


#1

How much wood could a wood chuck chuck if a wood chuck could chuck wood? pls help



#2
var canChuck = true;

if (canChuck) {
    console.log("Go wood chuck!");
} else {
    console.log("Call the wood chucker!");
}

The above is a basic model for an if-else statement. It consists of,

if             // if keyword
()             // a parameter block containing
a < b          // a conditional expression
{}             // a code block containing
return true;   // code statement for true
else           // else keyword
{}             // a code block containing
return false;  // code statement for false

Eg.

if (conditionalExpression) {
    // do something for true
} else {
    // do something for false (default)
}

#3

This exercise consists of two elements, a function, and an included if-else statement. The function takes one parameter, numHours which will be examined by the program and responded to accordingly.

First the function and a sample function call:

var sleepCheck = function (numHours) {
    // if-else statement code
};
sleepCheck(10);

Now we can work on the if-else statement...

    if (numHours >= 8) {
        return "__provided_text__";
    } else {
        return "__provided_text__";
    }

Put the above together and fill in the missing text. Don't forget to include the remaining two function calls...

sleepCheck(5);
sleepCheck(8);