4.Computer choice:Part 2


#1

I am not able to get a solution for my problem, i have visited other links but couldn't find the best answer suited for my problem.

This is my code:

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

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 {
console.log("scissors");

}

Error: Syntax error, Invalid or unexpected token.

I would be glad if you anyone could help me.


#2

you need a semi colon instead of a :


#3

You have to close string in the prompt (add " at the end of the string):

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

And there is a colon at the end of this line:

console.log("rock"):

I guess that you meant to use a semicolon.


Your code does not have now any syntax errors. You should read again instructions and make sure that your code completely implements them.


#4

1/ You didn't close your string in your prompt.
2/ You have a colon after console.log("rock"): //<==Here! change that to a semi colon.
3/ Doesn't the instructions tell you to equate computerChoice to "rock" or "paper" or "scissors" based on your conditions?

//for example
else if (computerChoice > 0.34 && computerChoice<=0.66) {
    computerChoice = "paper";
}

#5

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{
console.log("scissors");}

This worked for me now.


#6

and arent we supposed to use "console.log" command for printing rather than "computer choice=paper"

I dont know the difference and i think console.log is only what i have come across in these chapters.

Sorry if i am wrong


#7

You'll need to compare computerChoice with your input in the next few steps. Hence why they asked you to equate your computerChoice rather than log it. But if this works, it works. Good job :slight_smile:

The "rock", "paper" and"scissors" will still show when you have something like "computer choice=paper" because you already have console.log(computerChoice); before your if statements. So why type console.log again?


#8

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