"Rock, Paper, Scissors" Computer Choice Part 2 - else Syntax


#1

Hello codecademy peeps,

I'm working on Rock Paper Scissors project, and I'm getting "Syntax Error: Unexpected token else"

I'm not sure what is wrong with my else block, any help to point out the issue would be appreciated!

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

//computer choice rock
var computerChoice = Math.random(); {
console.log(computerChoice);
if (computerChoice <= 0.33) {
alert("rock");

}

computerChoice("rock")
else if (computerChoice <= 0.66) {
alert("paper");
}
computerChoice("paper")
else {
computerChoice = "scissors";

}

}

Thanks!


#2

var userChoice = prompt ("Do you choose rock, paper or scissors?")
var computerChoice = Math.random();

console.log(computerChoice);

if (computerChoice = 0-0.33) {
console.log("rock");
}
else if (computerChoice = 0.34-0.66) {
console.log("paper");
}
else if (computerChoice = 0.67-1) {
console.log("scissors");
};


#3

When I run your code, it comes up as this:
0.7296300050455917
rock

instead of substituting the long number for its reassigned value of scissors... Any reason why?


#4

just ran it again and it's still not recognizing it as scissors...

0.866335891411522
paper

I even changed your code a bit:

var userChoice = prompt ("Do you choose rock, paper or scissors?")
var computerChoice = Math.random();

console.log(computerChoice);

if (computerChoice <= 0.33) {
console.log("rock");
}
else if (computerChoice = 0.34-0.66) {
console.log("paper");
}
else if (computerChoice >= 0.67) {
console.log("scissors");
};


#5

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
//console.log(computerChoice);
if(computerChoice > 0 AND computerChoice < 0.33)
{
computerChoice = "rock";
}
else if(computerChoice > 0.34 AND computerChoice < 0.66)
{
computerChoice = "paper";
}
else
{
computerChoice = "scissors";
}

Where am I going wrong ?? It's showing problem with my syntax. Please help.


#6

I figured it out like this

var userChoice = prompt ("Do you choose rock, paper or scissors?")
var computerChoice = Math.random();

console.log(computerChoice);

if (computerChoice <= 0.33 ) {
console.log("rock");
}
else if (computerChoice > 0.34 && computerChoice < 0.66) {
console.log("paper");
}
else {
(computerChoice == 0.67-1)
console.log("scissors");
};


#7

I got around the coding for the computer choice like this. However, even though I "finished the section" and it displays the proper response I am still somewhat confused. The instructions say we are changing the value of the variable, but from what I can tell we are simply instructing the computer to recognize the value being presented by Math.random and act accordingly. Does this count as actually changing the value of the variable?


#8

you only have 2 conditions in this code where the 3rd is missing, and yes it is changing the value if you try the same code many times you'll see, don't go to the next step when you got next button close it and run the code again you'll see the value is changing.

Try this , it will work

var userChoice = prompt ("Do you choose rock, paper or scissors?")
var computerChoice = Math.random();

console.log(computerChoice);

if (computerChoice <= 0.33 ) {
console.log("rock");
}
else if (computerChoice > 0.34 && computerChoice < 0.66) {
console.log("paper");
}
else {
(computerChoice == 0.67-1)
console.log("scissors");
};


#9

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