Computer always responds with 'Rock'


#1


Build Rock Paper Scissors


It says I got it correct and to move on, but every time I put in a userChoice, it responds with 'rock'. So I know I did something wrong


Replace this line with your code. 
var userChoice = "Do you choose rock, paper or scissors?"
prompt(userChoice)
var computerChoice = Math.random(3)
{
    console.log(computerChoice)
{
}
if(computerChoice >=0 || computerChoice <=0.33 )
{
var computerChoice = "rock";
console.log(computerChoice)
} 
else if(computerChoice >= 0.34 || computerChoice <= 0.66)  
{
    var computerChoice = "paper";
    console.log(computerChoice) 
}
else(computerChoice >= 0.67 || computerChoice <=1)
{
var computerChoice = "scissors";
    console.log(computerChoice)
}
}


#2

It may be the fact your code is a bit over complicated, you only need to right one comparison in your if/ else. There is also no need to put a number inside Math.random(). Use my code below as a example.

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

else(computerChoice >= 0.67); {
    console.log("scissors") 
    }

If that solved it please mark my response as the solution :slight_smile: If it didn't it may be a bug, this course is getting removed this summer.


#3

Actually more likely it's the fact that after each if/ else if you make computer choice a variable. So after you do this:

var computerChoice = "rock";
console.log(computerChoice)

It makes the computer choice always rock.

The console should really pick you up on that and it's dumb how it accepted that as the answer.


#4

oh, i'm an idiot. haha thank you


#5

Haha, you're welcome. Please be so kind as to mark my reply as the solution?


#6

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