Why it isn't working?


#1

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 === "paper") {
       if(choice2 === "rock"){
           return "paper wins";
       }
       else if (choice1==="scissors"){
        if(choice2 === "rock"){
            return "rock wins";
        } else {
            return "scissors wins";
        }
    }
      
    } 
        else {
        return "paper wins.";
    }
};
compare(computerChoice,userChoice);

#2

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on

  • the build of the IF ELSE-IF statement structure
  • executing the compare function

#3

still not working :grin:


#4

Please present the code you are using now.....


#5
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==="paper"){
return "paper wins";
}
else {
return "rock 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";
}
} else {
return "rock wins";
}
};
compare(computerChoice,userChoice);


#6

that's the same problem in my case @rafid1


#7

:grin: :persevere: :grin:


#8

@rafid1,

var compare=function(choice1,choice2){
    if(choice1 === choice2){
        return "The result is a tie!";
    }

    else if (choice1==="rock") {
        if(choice2==="paper"){
            return "paper wins";
        } 
        else {
            return "rock 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";
        }
    }
     //else {
     //return "rock wins"; 
     //}
};

===========================================

Please read
http://www.codecademy.com/forum_questions/559dcb4be39efe550f00006b
and concentrate on

•executing the compare function

#9

404 error

This page doesn't exist.

Would you like to learn about HTTP errors?


#10

what is the problem with this?

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==="paper"){
return "paper wins";
}
else {
return "rock 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";
}
}
};
compare(computerChoice,userChoice);


#11

hey ?

and concentrate on

•executing the compare function

what does this mean?


#12

try console.log(compare(userChoice, computerChoice));