Error is coming again n again


#1


#2

try putting a space between elseif to make else if


#3

still not working.....


#4

Can you copy and paste your code here rather than a screenshot so I can run it?


#5

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


#6

if that still doesnt work take a look here, this is what I passed with


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";
}


#7

Else is the default case so it works for everything that is not specified in if or else if meaning it doesn't need a condition on its own and having one my lead to an error:


#8

I did as per your instructions.
but stil is is not working


#9

Could you post the updated code?


#10

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


#11

After readig your given link i found that else do not contain any condition so in the else part i removed the condition and It worked
Thank you