Codecademy Intro to Objects Review: The Story So Far Answer

March 23, 2012 — 2 Comments

Someone e-mailed and asked for help on this section, so here’s my source code / answer.

Section 1.3: …And the good!

/*
Michael Le (username: mikele)
Codecademy Answers / Source Code
Introduction to Objects:
1.3 Review: ...And the good!
*/
//for loop iterating from 1-20
for(i=1;i<=20;i++){
    
    if(i%3===0){
        //if divisible by 3 and 5 print FizzBuzz
        if(i%5===0)
            console.log("FizzBuzz");
            
        else
            console.log("Fizz");
    }
    else if(i%5===0)
        console.log("Buzz");
    //if not divisible by 3 nor 5 print the number
    else
        console.log(i);
}

1.4 I have to celebrate you baby answer / source code

/*
Michael Le (username: mikele)
Codecademy Answers / Source Code
Javascript Intro to Objects I:
1.4 I have to celebrate you baby.
*/
var getReview = function (movie) {

//use switch statement
switch(movie){
    
    //because you are using RETURN, you do not need BREAK;
    case "Matrix":
        return "good trip out";
    
    case "Princess Bride":
        return "awesome date night movie";
    
    case "Welcome to America":
        return "Amjad's favorite";
    
    case "Remember the Titans":
        return "love the sports";
    
    case "Why do I look like I'm 12?":
        return "The Ryan and Zach Story";
    
    case "Fighting Kangaroos in the wild":
        return "Token Australian movie for Leng";
    
    default:
        return "I don't know!";
    
}
}

Mike

Posts Twitter Facebook

My name is Michael Le, and I am a web developer.

2 responses to Codecademy Intro to Objects Review: The Story So Far Answer

  1. It doesn’t work I tried it!!

  2. Really enjoy seeing how other people solve the same problems when the problems have many solutions.
    Here’s the code I used for Section 1.3:
    for (i = 1; i <= 20; i++) {
    //if multiple of 3 AND 5 print FizzBuzz
    if (i % 3 === 0 && i % 5 === 0) {
    console.log(“FizzBuzz”);
    }
    //if multiple of 5 print Buzz
    else if (i % 5 === 0) {
    console.log(“Buzz”);
    }
    //if multiple of 3 then print Fizz
    else if (i % 3 === 0 ) {
    console.log(“Fizz”);
    }
    //if not a multiple of 3 or 5 then print number.
    else {
    console.log(i);
    }
    }

    As for Section 1.4, I spent an hour on that code before I realized it wasn’t working because I forgot the : after default.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.