Code Your Own Adventure 2. I Have No Idea What I'm Doing


#1


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

Error code: Oops, try again. There was a problem with your syntax.

 var user = prompt("What is your name adventurer?").toUpperCase();
switch(user) {
    case 'Steve Rodgers':
        console.log("Hail Hydra");
        break;
    case 'Ethan':
        console.log("Welcome Hero.");
        break;
    case 'John':
        console.log("The destroyer of worlds?! My humble apologies please take whatever you need.");
        break;
    default:
    console.log("Welcome traveler.");
}
var year = prompt("What year is it?!").toUpperCase();
var month = prompt("And the month?!").toUpperCase();
switch(year) {
    case 2016:
        if(month = 1; month < 6; counter++) {
        console.log("Good, there's still time!");
        } else {
            console.log("I've been away for too long! It's too late!");
        }
        break;
    case 2017:
        console.log("There's no more time I'm sorry.")
}

I have absolutely no idea as to why this isn't working. Please help.


#2

I removed all .toUpperCase() by the way.


#3

Hi this part of your code

var year = prompt("What year is it?!").toUpperCase();
var month = prompt("And the month?!").toUpperCase();
switch(year) {
    case 2016:
        if(month = 1; month < 6; counter++) {
        console.log("Good, there's still time!");
        } else {
            console.log("I've been away for too long! It's too late!");
        }
        break;
    case 2017:
        console.log("There's no more time I'm sorry.")
}

first your case should have as condition...

case condition:
    #Do something
break;

strings so it will be

switch(year) {
case "2016":
   ...
break;
case "2017":
  ...
break;

}

then this line

if(month = 1; month < 6; counter++)

what do you want to do a if statement or a for loop.


#4

I want it to be an if statement but I need a for loop so it includes numbers 1-6


#5

you could put the if and else statement inside the for loop like that

for ( var x = 1; x <= 6 ; x++ ) {
   if (condiiton) {
      #do something
   }
   else {
      #do something
   }
}

#6

Okay, I'll try that thanks for the help!


#7

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