8. What if choice1 is scissors


#1

I seemingly passed part 7 by deleting the extra code.
I keep getting "SyntaxError: expected expression, got keyword 'else'"
Following on from uncommenting the top section, I still get nothing.
Thank you in advance.

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(userChoice, computerChoice){
if(choice1 === choice2){
return "The result is a tie!";}
else if(choice1 === "paper"){
if (choice2 === "rock"){
return "Paper wins"};
else{
return "Scissors wins"};
};
else(choice1 === "rock"){
if (choice2 === "Paper"){
return "Paper wins";}
else{
return "Rock wins";}
;}
if (choice1 === "scissors"){
if (choice2 === "rock"){
return "Rock wins";}
else{
return "scissors wins";}
;}
;}

console.log(compare);


#2

@wookiestormtrooper here is your code corrected I have inserted comments on where the mistakes were

var userChoice = prompt("Do you choose rock, paper or scissors?").toLowerCase();
var computerChoice = Math.random();

if (computerChoice < 0.34) {computerChoice = "rock";}
else if(computerChoice <= 0.67) {computerChoice = "paper";}
else {computerChoice = "scissors";} 

console.log("Computer: " + computerChoice);

//here in this function remember that the parameter you provide
//as the function arguments must be what you use in the implementation
// in your case you are using (userChoice, computerChoice) as your
//arguments but in your implementation(body) you are using
//(choice1, choice2) which is an error because these two variables have not been defined anywhere

var compare = function(choice1, choice2){
                if(choice1 === choice2){return "The result is a tie!";}
                else if(choice1 === "paper"){
                    if (choice2 === "rock"){return "Paper wins";}
                    else{return "Scissors wins";}
                }
                
                //Here you wrote else
                // but the else block takes no conditions
                // should be else if ()
                else if(choice1 === "rock"){
                    if (choice2 === "Paper"){return "Paper wins";}
                    else{return "Rock wins";}
                }
                
                //here you wrote if
                //try to make it else if()
                else if (choice1 === "scissors"){
                    if (choice2 === "rock"){return "Rock wins";}
                    else{return "scissors wins";}
                }
            };

console.log(compare(userChoice, computerCh

#3

@wookiestormtrooper,
Please read
= http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on

  • the creation of the compare function
  • the required =all-lowercase= return string Value's
  • the build of the IF ELSE-IF ELSE-IF statement structure ( NO semi-colons-; on your IF ELSE-IF strucuture )
  • the excution of your compare =function=

#4

Thanks heaps bud.
Looked over the comments and such.
Really appreciate it, thank you :smile: