{ Debugging Exercises. }

Answer the following questions:

Explain what type of error will be thrown, why the error is occuring, and how to fix it:

1.

person;

2.

var data = {};
data.displayInfo();

3.

var data = {};
data.displayInfo.foo = "bar";

4.

function data(){
    var thing = "foo";
}
data();
thing;

Part II

Fix the broken code and explain what was wrong:

1.

for(var i=0; i > 5; i++){
    console.log(i);
}

2.

function addIfEven(num){
    if(num % 2 = 0){
        return num + 5;
    }
    return num;
}

3.

function loopToFive(){
    for(var i=0, i < 5, i++){
        console.log(i);
    }
}

4.

function displayEvenNumbers(){
    var numbers = [1,2,3,4,5,6,7,8];
    var evenNumbers = [];
    for(var i=0; i<numbers.length-1; i++;){
        if(numbers % 2 = 0); {
            evenNumbers.push(i);
        }
        return evenNumbers;
    }
}
displayEvenNumbers(); // should return [2,4,6,8] 

// HINT - eight things need to be changed here for this to work!
// Start by fixing the syntax errors and then run the function to see what your output is.

Solutions

You can find solutions to the exercises here

When you're ready, move on to Nested Objects

Continue

Get 100+ hours of free content, tutorials, and screencasts

Send us your email, and we'll give you a confirmation code to unlock all of our materials. No spam, we promise.