Sector 8


#1

var userChoice = prompt("Do you choose rock, paper or scissors?");
var compare=function(userChoice,computerChoice)
{
if (userChoice === computerChoice) {
return "The result is a tie!";
}
else if (userChoice === "rock")
{
if (computerChoice === "scissors")
{
return "You win!";
}
else
{
return "Computer wins!";
}
}
else if (userChoice === "paper")
{
if (computerChoice === "rock")
{
return "You win!";
}
else
{
return "Computer wins!";
}
}
else if (userChoice === "scissors")
{
if (computerChoice === "rock")
{
return "undefined";
}
else
{
return "You win!"
}
}
}
var computerChoice = 0.35;
if (computerChoice < 0.34) {
computerChoice = "rock";
} else if(computerChoice <= 0.67) {
computerChoice = "paper";
} else {
computerChoice = "scissors";
}
console.log(compare(userChoice,computerChoice));

this comes up, By the way i put undefined cuz it told me 2

Oops, try again. Your code returned 'undefined' instead of 'undefined' when the inputs are scissors and rock


#2

Undefined is just what the code check program returns to you instead of giving you the answer. So really that line should say:

return "rock wins";

One of the other problems is that you are using userChoice and computerChoice INSIDE your function instead of choice1 and choice2. Your function line should say:

var compare = function(choice1, choice2){

You should also be using choice1 and choice2 in your if/else statements instead of userChoice and computerChoice
Also, at the very end of your code instead of using

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

you can just go with:

compare(userChoice, computerChoice);

Hope this helps.


#3

Ignore that undefined part of the error message I guess that assumes that this part is not yet implemented. What is important is the part where it says which case makes trouble which is in your case scissors,rock. Probably it expects to see rock wins, aso instead of computer and user wins.