Build "Rock, Paper, Scissors"


#1

Struggling to complete 6. What if choice1 is rock?
I have followed the screen but its saying my syntax has a problem

/*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 === "scissors") {
    return "rock wins";
}
else {
    return "paper wins";
}

}


#2

You're one closing curly brace shy of closing the compare function.


#3

And the curly fry might just be in that area...


#4

Cheers Biff75,

Right after I posted I realised my error.

Thank you


#5

Stuck at the last hurdle! Being dense no doubt.

See code below, ive forgotten how to call userChoice and computerChoice as arguments


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

}
}


RETURNS:
Oops, try again. Make sure to call your compare function with userChoice and computerChoice as the arguments!


#6

You need to build a compare statement that console.logs the userchoice and the computerchoice to the screen so a basic outline of that would be:

console.log(compare(what, what));


#7

perfect thank you bibleman13


#8

These curly fries are killing me


#9

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