Trouble with the Code Your Own Adventure 2 JavaScript activity


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
So, once I answer the prompt with a response that show in both a case and in my if/else if statement, it only shows the response from the case. My responses from the if/else if/else statement won’t pop up. I’ve already moved it around a few times just in case the placement was wrong, but that only makes it worse. Then it says that my ‘SING’ case is not defined. It allows me to complete the assignment, but it doesn’t show everything that I want it to display to the player;

```

Replace this line with your code.
var user = prompt(“What is your favorite thing to do?”).toUpperCase();

switch(user) {
case ‘READ’:
console.log(“I like to read too.I like to imagine different ways that the story could happen.”);
break;

case 'SWIM':
    console.log("I enjoy swimming too, but I don't really get to do it that often. The YMCA that my family used to swim at closed down so there aren't any places to go swimming that are near.My Pa Pa Reado has a swimming pool but my sister and I only go when my dad is in town."); 
break; 

case 'WATCH TV':
    console.log("I like it too, but I go on the computer more now. I like to watch Steven Universe, Everybody Hates Chris, We Bare Bears, Star vs the Forces of Evil, and some others. Just make sure that you don't watch too much.");
break;

case 'CODE':
    console.log("Me too, though i'm sure that pretty obvious. I gave p on it a while back because one of my programs wouldn't work but it seems like lately everyone wants to be a coder but just thrilling for me to learn something new and be able to apply it like I am now. I decided to pick it back up recently and i'm having a great time");
break;

case 'RUN':
    console.log("It's kinda fun for me to push myself at school and set goals for my running but I don't really exercise much in my free time. I do get random bursts of energy at run and I just run around like a crazy person for a few seconds.");
break;

case 'SLEEP':
    console.log("Well that's not really doing anything but you know what they say different strokes for different folks. Plus, I like to sleep too.");
break;

case 'PLAY VIDEO GAMES':
    console.log("Did you know that people who play video games have better attention to detail and slowed brain aging. Plus you're probably more likely to survive a zombie apocalypse.");
break;

case 'DANCE':
    console.log("I dance sometimes for fun. I have a sister who dances at her college.");
break; 

case 'SING':
    console.log("I did karaoke at my school on the last day before winter break started. I was shaking the whole time.");
break;

case 'LISTENING TO MUSIC': 
    console.log("I listen to music all the time. Lately I've been listening to this song called Virtual Riot - Idols(EDM Mashup). It really cool you should check it out.");
break; 

default: 
    console.log("I wasn't expecting that but it sounds awesome.");
    
    if(SING && DANCE){
        console.log("Maybe you could become some sort or pop star or famous performer and inspire the world with your uplifting and eye opening music. Throw some conscious music in there too if you do become one!");
    }
    else if(READ || CODE){
        console.log("You're probably a really creative person! You could become an author or software engineer!");
    }
    else{
        console.log("You could probably turn that into something creative that you could make a living off of, or you could just keep having fun with it as a hobby, who knows!");
    }   

}

<do not remove the three backticks above>

#2

break ends the switch statement. To get the if to evaluate, you would need to move it outside of the switch() { }.

Also the if statements need work. For example, to check a string in a variable you would use this type of syntax: if (var === 'string' || var === 'other string')


#3

I understand the first part, but could you please explain the last part of your statement. Also, thank you for replying.


#4

Happy to help!

if (READ): means “if the variable READ contains True, do what follows.” if (var === 'READ'): means “if the variable var contains 'READ', do what follows.”


#5

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