Is this correct?


#1


Replace this line with your code. 
var userChoice = prompt("Do you choose rock, paper or scissors?")

var computerChoice = Math.random()

if (computerChoice < 0.34) {
    computerChoice = "Rock"
}
else if (computerChoice <= 0.66) {
    computerChoice = "Paper"
}
else {
    computerChoice = "Scissors"
}


#2

Hi DO you get any error?


#3

Syntactically it is correct. The strings that are asked for are lower case, though... rock, paper, scissors.


#4

This is the new code (finished) It's letting me pass but it's not printing out who wins...

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"
}
else {
    return "Scissors wins"
}

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


#5

This will print [Function] to same way this will print, [object Object]

a = {};
console.log(a.toString());

You are on the right track, though, and just need to complete the call expression.

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

It is necessary that we pass the two choices to the compare function.


#6

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