I passed until the last exercise (9.Next Steps) but it doesn't let me go any forward


#1

When i hit "Save & submit code" in the console it states "SyntaxError: Illegal return statement" Can someone help me, please? Thanks.


#2

Can you post your code sir? Thanks!


#3

This is my code good sir. Thank you for helping. Really need it from time to time.

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice)
if(choice1 === choice2) {
return "The result is a tie";
}

else if(choice1 === "rock") {

if(choice2 === "scissors") {
    return "rock wins";
}
else {
    return "paper wins";
}

#4

So these are your problems.

First

You forgot a bracket at then end to close your else if statement.

Second

Try changing all your returns to console.log();

Hope this helped!


#5

Sorry, but, i don't see where i should add a bracket at the else if statement.
else if(choice1 === "rock") {

if(choice2 === "scissors") {
    console.log("rock wins");
}
else {
    console.log("paper wins");
}

#6

Btw, now the console log states "SyntaxError: Unexpected end of input"


#7

At the end like at the end of your code :laughing: Ok let me check this in more detail. I will come back soon with 100% Solution


#8

My bad, just added it, and it worked. Another problem got now. ReferenceError: choice1 is not defined


#9

FML, this is way harder than i thought. I work as a game tester, and damn now I understand why the developers have a hard time fixing the bugs and it takes about 1-3 days to fix one.


#10

DId you get the problem? And yeah , I HATE :bug:'s. Ahhh dont talk about them :confounded:


#11

Noticed two other problems. The pc always chooses "rock", and still the console still states "ReferenceError: choice1 is not defined!"


#12

Can you post your updated code? Thankyou


#13

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
}
else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice)
if(choice1 === choice2) {
console.log("The result is a tie");
}

else if(choice1 === "rock") {

if(choice2 === "scissors") {
    console.log("rock wins");
}
else {
    console.log("paper wins");
}

};


#14

Ok i will edit this post with the solution to your problem soon!


#15

Btw, if you're really 14, you're a genius man. I'm 20 and i'm considered a genius in my country. Kids at 14 here don't know poopy. Keep coding! I have to go to the shop but i'll get back in about 15 minutes. Thank you for helping me! I would of despair if i wouldn't made it!


#16

I mean its kinda/completely (No Offense), off. you needed to create a compare function and all that to actually define the code. Since this is the last step, first i still passed with your code altough its giving me that error but if your desperate to fix code here it is(Please understand what its going on there before just copy pasting so you could become a web developer some day!):

And yeah im 14! Thanks a lot , here is a flappy game i made using a cool javascript framework, give me any suggestions for what i should fix.

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
} console.log("Computer: " + computerChoice);
    var compare= function(choice1, choice2){
        if(choice1===choice2){
            return"The result is a tie!";
            }
        if(choice1 === "rock")
            {
                if( (choice2 === "scissors")){

                    return( "rock wins");}
                else {var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
if (computerChoice < 0.34) {
	computerChoice = "rock";
} else if(computerChoice <= 0.67) {
	computerChoice = "paper";
} else {
 	computerChoice = "scissors";
} console.log("Computer: " + computerChoice);

var compare = function(choice1, choice2) {
if (choice1 === choice2) {
    return "The result is a tie!"
} else if ( choice1 === "rock") {
    if (choice2 === "scissors") {
        return "rock wins"
    }
    return "paper wins"
 } else if (choice1 === "paper") {
    if (choice2 === "rock"){
        return "paper wins"
        }
        else {
        return "scissors wins"
    }
}  else if (choice1 === "scissors") {
    if (choice2 === "rock"){
         return "rock wins"
        }
        else {
        return "scissors wins"
    }
}

};
                    return( "paper wins");
                        }
            }
            else
            { 
                if(choice1 === "paper") {
                                
                    if(choice2 === "scissors" ){

                        return( "scissors wins");}
                    else {
                            return( "paper wins");
                            } 
                }
                else
                {
                 if(choice1 === "scissors" ) {
                     
                     if(choice2 == "paper")

                        return( "scissors wins");}
                    else {
                            return( "rock wins");
                            }    
                    }
                                


            }
}

#17

Remember that this is a family friendly forums. Please keep your posts PG. Thank you! :+1:


#18

Thanks a lot. This really fixed the problem. But from what i see, and i might be wrong but, shouldn't the code give me back an answer like "rock wins" or something like that after it displays what the computer chose?


#19

Yea it should. Does it?


#20

No it does not... :frowning: