Stucked!


#1

Hi All,
I am stucked in "Rock, Paper, Scissors" assignment (lesson 3.1). I have tried all the best possibilities even copied and pasted the variables provided left hand side but it is not getting resolved and throwing below error.
I have taken the help of previous solution provided in this forum also.
Please help me out.Thanks in advance.

Error:
Oops, try again. Did you make a variable called computerChoice?

Questions:
1. Under your previous code, declare a variable called computerChoice and make it equal to Math.random().
2. Print out computerChoice so you can see how Math.random() works. This step isn't needed for the game - just useful for learning!

Code:
function playFunction() {
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";
}

var compare = function(choice1, choice2) {
if(choice1 === choice2) {
alert("The result is a tie!");
}
if(choice1 === "rock") {
if(choice2 === "scissors") {
alert("rock wins");
} else {
alert("paper wins");
}
}
if(choice1 === "paper") {
if(choice2 === "rock") {
alert("paper wins");
} else {
if(choice2 === "scissors") {
alert("scissors wins");
}
}
if(choice1 === "scissors") {
if(choice2 === "rock") {
alert("rock wins");
} else {
if(choice2 === "paper") {
alert("scissors wins");
}
}
}
}
};
console.log("User Choice: " + userChoice);
console.log("Computer Choice: " + computerChoice);
compare(userChoice, computerChoice)
}


#2

@digitalcoder67996,
-1
Do not pack the creation of your computerChoice in a function......
-2
In your compare function they require the use of the return statement

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 )