Need help with building Rock, Paper, Scissors


#1

Hi,

Here is my code. I don't know what I'm doing and I imagine there's lots to be fixed. Can anyone help?

var userChoice = prompt("Rock, Paper, or Scissors?");
var computerChoice = Math.random();

if (computerChoice < .34) {
     return "Rock";
}
else  if {
    (computerChoice >= .34 && < .66) {
         return "Paper";
    }
}

else  {
     (computerChoice >= .67 && <= 1.0) {
         return "Scissors";
}

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

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

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

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

console.log ("User Choice:" + " " + userChoice);
console.log ("Computer Choice:" + " " + computerChoice);
compare (userChoice, computerChoice);

#2

@paspencer20,

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

Thanks!! I'm going to read some more and then start over.


#4

A post was split to a new topic: There should be an else here but the computer doesn't like it for some reason