Rock, Paper, Scissors


#1

What am I doing wrong?

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

var compare = function(choice1,choice2){

if (choice1 === choice2) {
    return "The result is a tie!";

}

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

}

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

}

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

}


#2

@bexpet,
To get an idear of how the code should look like....

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

  • the creation of the compare function
  • the truth-table
  • the build of the IF ELSE-IF statement structure as part of the compare FUNCTION-BODY
  • the execution of the compare function (keeping in mind that the return statement is used )

#3

No idea WHAT I'm DOING WRONG!!!!

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

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

;}

};


#4

@courseslayer54005,
In
https://discuss.codecademy.com/t/rock-paper-scissors/52201/2?u=leonhard.wettengmx.n
have close look at
the build of the IF ELSE-IF statement structure as part of the compare FUNCTION-BODY

and be careful with the usage of semi-colon's-;
as for the Javascript Interpreter the semi-colon-; is an End-of-Statement indicator.


#5

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

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

;}

};
wha the ■■■■ am I doing wrong
it keeps saying that scissors wins when it shoulnt


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.