4. Computer Choice: Part 2 - Help im stuck


#1

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

var computerChoice = Math.random();
console.log(computerChoice);
if (computerChoice <= 0.33){
alert("Rock");
}else if(computerChoice <= 0.66){
alert("Paper");
}else(computerChoice <=1){
alert("Scissors");
};
console.log("Computer" + computerChoice);

Oops, try again. There was a problem with your syntax.

please help idk what to do i changed the code 1.000 times


#2

The above is the syntax error. else is a default branch that takes no conditional.

if (condition1) {
    // branch if true
}
else if (condition2) {
    // branch if true
}
else {
    // default branch
}

Also, alert() is a one-off statement that does not store any value. We need to store the value, not output it.

computerChoice = "rock";
computerChoice = "paper";
computerChoice = "scissors";

#3

Thank you very much, that's gonna help me on the future


#4

can someone please help me figure out....what is the mistake in this code?
it appears "oops try again! there was a problem with your syntax."
please help!

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<=1) {
computerChoice="scissors";
}


#5

If you read the 2nd post in this topic, I believe you will solve the problem you're having.


#6

Make sense! Thank you!


#7

I am not sure what I did wrong...
var userChoice = prompt("Do you choose rock, paper or sissors?");
var computerChoice = Math.random();
console.log(computerChoice);
if (computerChoice <= 0.33){
computerChoice = "rock";
};
else if (computerChoice <=0.66){
computerChoice = "paper";
};
else{
computerChoice = "sissors";
};

it shows:
there was a problem with your syntax


#8

Move this console.log statement over to the last line

And here,

You wrote sissors instead of "scissors": .


#9

Thanks! I never knew i typed sissors instead of scissors! XD


#10

After I change you noticed above, it still shows syntax error...


#11

What do you mean? it's still not passing?


#12

yes. Still not passing


#13

you have 3 semicolons which are not needed


#14

There shouldn't be semi colons next to your closing brackets on all if statements,

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

#15

Is problem fixed? coolprogrammer2003


#16

Ic thanks. That helps me a lot.


#17

Yes. Problem fixed. Thanks :smiley:


#18