4. build rock paper scissors


#1

var userChoice = prompt("Do you choose rock, paper or scisso?);

var computerChoice =  Math.random();

if (computerChoice < 0.33) {
    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 === "rock") {

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

its saying SyntaxError: Invalid or unexpected token but i cant find where :confused: help please @stetim94


4 Build "Rock, Paper, Scissors"
#2

what you did in exercise computerChoice2:

if (computerChoice < 0.33) {
    computerChoice === "rock";
    } else if (computerChoice <= 0.67) {
        computerChoice === "paper";
        } else {
            computerChoice === "scissors";
             } console.log("Computer: " + computerChoice);

you should have updated the variable computerChoice with a string, to update/assign/re-assign a variable, use a single equal sign


#3

var userChoice = prompt("Do you choose rock, paper or scisso?);

var computerChoice = Math.random();

if (computerChoice < 0.33) {
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 === "rock") {

if(choice2 === "scissors") {
return "rock wins";
}
else {
return "paper wins";
}
}
}
compare(userChoice, computerChoice);

still now SyntaxError !!!! gggrrrr this code now making me angry !!! @stetim94


#4

if you are truly at exercise 4, like the topic you replied to, how can you already have all the code.

i just troubleshoot the most obvious problem first, seems there are more problems which you can't find, so i will help you further.

look at this line:

var userChoice = prompt("Do you choose rock, paper or scisso?);

a quotation mark (") is missing to close the strings


#5

hey! @stetim94 thank u so much now its working !!!! :relieved:


#6

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