Help with Rock Paper Sissors Computer Choice Part 2


#1


https://www.codecademy.com/courses/javascript-beginner-en-Bthev-mskY8/0/4?curriculum_id=506324b3a7dffd00020bf661#


I keep getting the same error message that something is wrong with the syntax. My exact code from the lesson is as follows...


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

var computerChoice = Math.random();

console.log(computerChoice);

if (computerChoice < 0.33) {
    computerChoice = "rock";
};

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

else {
    computerChoice = "sissors";
};


#2

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

var computerChoice = Math.random();

console.log(computerChoice);

if (computerChoice < 0.33) {
    computerChoice = "rock";
}

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

else {
    computerChoice = "scissors";
};

Here's what i changed: "sissors" to "scissors". Removed ; from lines inside if statement. Changed if else to else if.


#3

Excellent, fischt!

Thaks a lot!


#4

Hi, please help me verify exercise 8, I am lost. Thank you in advance!

here is what I did.
`
var userChoice = prompt("Do you choose rock, paper, or sissors?");
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 === "scissors") {
if (choice2 === "rock") {
return "rock wins";
} else {
return "scissors win";
}
} else {
if (choice2 === "rock") {
return "paper wins";
} else {
return "scissors win";
};
};
}`


#5

The very last thing you have typed is a mistake:

should just be };

Also you now need to call your compare function.


#6

You don't have to put a semi colon in between if statement and in javascript there is no condition statement like if else instead it else if so try and make the changes
`
if (computerChoice < 0.33) {
computerChoice = "rock";
}; remove this semicolon

if else (computerChoice <= 0.66) {
computerChoice = "paper";
}; remove this semi colon

Right changes

if (computerChoice < 0.33) {
computerChoice = "rock";
}
else if (computerChoice <= 0.66) {
computerChoice = "paper";
}
else {
computerChoice = "sissors";
};
```


#7

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