Unexpected token else in 6/9, what if choice1 is rock, build rock paper scissors


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/2?curriculum_id=506324b3a7dffd00020bf661 (6/9 : if choice1 is rock, build rock paper scissors)


The error: Unexpected token else (syntax error)


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


#2

Hello @csssolver98677,
could you please post your entire code?
This snippet seems to be correct.


#3

It could also refer to this else:

else if (choice1 === "rock")

are you sure your closed your else if of the previous exercise correctly? Please post your full code


#4

We would have to see the entire code to make any conclusions. :smirk:


#5

I thought i put that in, seems i didn't. Thank you :slight_smile:


#6

I finally got this project done. Check it out;
alert('This game is case sensitive!');

var ready = prompt('Are you ready to play?, please type "yes"');

if (ready =='yes'){
console.log(alert('Great, let\'s start?'));}
else {
console.log('We are going to miss you');
}
var pick = prompt('Please pick; Rock, Paper or Scissor?');

var computer = Math.random();
var comResult ='';
if(computer <= .33){
comResult ='Rock';
}
else if (computer <= .67){
comResult ='Paper';
}
else{
comResult ='Scissor';
}
console.log (pick+comResult);

first=pick;
second=comResult;

function compare (first,second){



if( first == second ){
    return 'Tie';
}  

else if(first=='Paper'&& second=='Rock'){
    return 'Paper wins';
}   

else if(first=='Scissor'&& second=='Rock'){
    return 'Rock wins';
}

else if(first=='Scissor' && second =='Paper'){
    return 'Scissor wins';
}  

else if(first=='Rock' && second == 'Paper'){
    return 'Paper wins';
}

else if(first=='Rock' && second =='Scissor'){
    return 'Rock wins';
}
else if(first=='Paper'&& second =='Scissor'){
    return 'Scissor wins';
}
else {
    return 'null';
}

};

alert(compare(first,second));


#7