Code your own adventure 2! - 5


#1


https://www.codecademy.com/courses/javascript-beginner-en-ZA2rb/0/5?curriculum_id=506324b3a7dffd00020bf661#


My code is not logging if/else results to console.
Can some please help explain why not?
Am I not supposed to use numerical values to differentiate my cases?


Replace this line with your code. 
var user = prompt ("What's your favorite month?").toLowerCase();
switch (user) {
    case 0 :
         if(user == ("january"|| "febuary"|| "march" || "april")) {
             console.log("That is the first quarter of the year");}
             else{
                    console.log("Did you not Type a month1?");}
        break;
    case 1 :
        if (user == ("may" && "june")) {
            console.log("Ahh the start of summer. how nice.");}
            else {
                    console.log("Did you not type a month2?");}
        break;
    case 3 :
        if (user  (! ("july" || "august" || "september" || "october" || "novemeber" || "december"))) {
        console.log("You're not into 2nd half of the year, are you?");}
        else {
            console.log("Did you not type a month3");}
        break; }


#2

As your code currently is you're checking the user variable for the numbers 0, 1, or 3. Try checking for the values you expect to be in there. You can utilize fall-through to perform similar operations for groups of results:

switch(game) {
    case "Bioshock":
    case "Rise of the Tomb Raider":
    case "Thimbleweed Park":
        console.log("That's a great game!");
        break;
    case "Dragon Age II":
    case "Clive Barker's Jericho":
        console.log("I didn't really like that game..");
        break;
    default:
        console.log("I haven't played that one.");
        break;
}

#3

I was off by not defining cases.

I defined my cases & created new var prompts within them allowing me to open up to utilizing logical operators decided which response the console would return.

var user = prompt ("What's your favorite month?").toLowerCase();
switch (user) {
case 'january' :
var fresh = prompt ("Is this because you're looking for a fresh start?(Yes or No)").toLowerCase();
var over = prompt ("Or is it because you just wanted the holiday season to be over?(Over or No)").toLowerCase();
if(fresh === "yes" && over==="over"){
console.log("Well fortunately for you, it is starting.");
}else if (fresh ==="no" || over==="over") {
console.log("Well what is that makes it your favorite?");
}else{
console.log("Well this is a new year");
}
}


#4

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