Whats wrong in my code?


#1

Here's my code:
var user = prompt ("Are you ready to go through jungle?").toUpperCase();

switch (user) {
case 'river':
var jump = prompt ("Are you ready to jump?").toUpperCase();
var swim = prompt ("Can you swim?").toUpperCase();

    if (jump === 'YES' && swim === 'YES') {
        console.log("Great you have crossed river);
    }
    else if (jump === 'YES' && swim === 'NO') {
        console.log("Oh no you can't swim");
    }
    else {
        console.log("you failed in crossing river");
    }

break;

case 'valley':
    var cross=prompt ("Are you ready to cross valley?").toUpperCase();
    var scared = prompt ("Are you scared?").toUpperCase();
    if (cross === 'YES' || scared === 'YES') {
        console.log("Nice keep up!");
    }
    else {
        console.log("Guess you can't do it at all");
    }


break;

case 'tree':
    var climbUp = prompt("Can You climb tree?").toUpperCase();
    var climbDown = prompt ("Can you get down now?").toUpperCase();

    if (climbUp === 'YES' || climbDown === 'YES' ) {
        console.log("Good you have succeded.");
    }
    else {
        console.log("Better luck next time. ");
    }

break;

default :
    console.log("Great! you didn't face any obstacles");

}

it gives me syntax error saying:
SyntaxError: unterminated string literal

plz help i don't get what's wrong with it


#2

You need to put your yes's and no's in quotations.

if (jump === "YES" && swim === "YES") {

etc.


#3

NO it doesn't work i tried what does putting in quotation have to do with string


#4

The words YES and NO on it's own, is an object. You need to put all of them in quotations for them to be made a string.

Also, your console.log's are messed up. Follow the first line here:
Correct: console.log("Hello World");
Wrong: console.log = ("Hello World");
Wrong: console.log("Hello World


#5

@jaaakee i fixed console.log but still same issue and i have put the yes and no in quotations already but still nothing changes same error over and over basically its about string but i am unable to find it .


#6

Show me your code now and the exact error you are getting.


#7

var user = prompt ("Are you ready to go through jungle?").toUpperCase();

switch (user) {
case 'river':
var jump = prompt ("Are you ready to jump?").toUpperCase();
var swim = prompt ("Can you swim?").toUpperCase();

    if (jump === 'YES' && swim === 'YES') {
        console.log("Great you have crossed river);
    }
    else if (jump === 'YES' && swim === 'NO') {
        console.log("Oh no you can't swim");
    }
    else {
        console.log("you failed in crossing river");
    }

break;

case 'valley':
    var cross=prompt ("Are you ready to cross valley?").toUpperCase();
    var scared = prompt ("Are you scared?").toUpperCase();
    if (cross === 'YES' || scared === 'YES') {
        console.log("Nice keep up!");
    }
    else {
        console.log("Guess you can't do it at all");
    }


break;

case 'tree':
    var climbUp = prompt("Can You climb tree?").toUpperCase();
    var climbDown = prompt ("Can you get down now?").toUpperCase();

    if (climbUp === 'YES' || climbDown === 'YES' ) {
        console.log("Good you have succeded.");
    }
    else {
        console.log("Better luck next time. ");
    }

break;

default :
    console.log("Great! you didn't face any obstacles");

}

here's the code
and
this is error : SyntaxError: unterminated string literal


#8

console.log("Great you have crossed river);

You forgot to close this sentence with a quotation. You also need to add a closing curly brace at the end of your code.


#9

thank you problem is solved but no matter what i enter why does go to default always.


#10

Copy all of your code, go to this website, paste all of your code into the text box, and click the "Beautify JavaScript or HTML" button. Once you have done that, copy it and paste it into the Codecademy lesson.


#11

Yeah the looks nice but still why does it always go to default instead of other cases. if i say river it should go to river but it goes to default.


#12

Weird. It doesn't do that for me. Once I used that website to fix the indentation it ran fine. Can you post the current code?


#13

var User = prompt("Are you ready to enter jungle?").toUpperCase();

switch (User) {
    case 'river':
        var jump = prompt("Are you ready to jump?").toUpperCase();
        var swim = prompt("Can you swim?").toUpperCase();

        if (jump === 'YES' && swim === 'YES') {
            console.log("Great you have crossed river");
        } else if (jump === 'YES' && swim === 'NO') {
            console.log("Oh no you cant swim");
        } else {
            console.log("you failed in crossing river");
        }

        break;

    case 'valley':
        var cross = prompt("Are you ready to cross valley?").toUpperCase();
        var scared = prompt("Are you scared?").toUpperCase();
        if (cross === 'YES' || scared === 'YES') {
            console.log("Nice keep up!");
        } else {
            console.log("Guess you cant do it at all");
        }


        break;

    case 'tree':
        var climbUp = prompt("Can You climb tree?").toUpperCase();
        var climbDown = prompt("Can you get down now?").toUpperCase();

        if (climbUp === 'YES' || climbDown === 'YES') {
            console.log("Good you have succeded.");
        } else {
            console.log("Better luck next time. ");
        }

        break;

    default:
        console.log("Great! you didnt face any obstacles");
        break;


}

#14

Put the case parameters in caps.

case 'TREE':
case 'VALLEY':

You set the prompts toUpperCase, so your cases should be in caps as well.


#15

Thank you code worked fine. those were really silly mistakes. any way do you know how to use js outside codecademy because i don't know how to run it outside.


#16

Yeah. That's one thing I don't really like about the lessons on Codecademy. They don't expand on the language by telling you how to run it outside of the website, extra resources, etc.

Go to "The Script Tag" part of this website. Stop around the part of the different language types in scripts.