Code runs but errors with Ops, try again


#1

var userChoice = prompt("Do you choose rock, paper or scissors?");
var computerChoice = Math.random();
// console.log (computerChoice)
if (computerChoice <0.34){
computerChoice = "rock";
}else if(computerChoice <=0.67){
computerChoice = "paper";
}
else{
computerChoice = "scissors";
}
var compare = function(choice1,choice2){
if(choice1===choice2){
return "The result is a tie!";
}
if(choice1==="rock"){
if(choice2==="scissors"){
return "rock wins";
}
else{
return "paper wins";
}
}
if(choice1==="paper"){
if(choice2==="rock"){
return "paper wins";
}
else{
return "scissors wins";
}
}
if(choice1==="scissors"){
if(choice2==="rock"){
return "rock wins";
}
else{
return "scissors wins";
}
}
};
compare(userChoice,computerChoice);

// Why do I get the error: Oops, try again. Did you set var computerChoice = Math.random() ? The capital // 'M' in 'Math' is important! I do have a capital M


#2

can you send a link? just for reference.


#3

Instead of doing two consecutive if statements, do
if(choice1==="rock" && choice2==="scissors"){


#4

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


#5

so I'm not sure why you have so much completed at this point. the assignment you sent the link to only asks for a couple of lines of code.

var userChoice = prompt("Do you choose rock, paper, or scissors?");
var computerChoice = Math.random();
console.log(computerChoice);

this is all that I have for the assignment.


#6

either the link is wrong or you just went way further then you needed to.


#7

I tired backing up to where the Math.random was called since that is the error message I'm receiving.


#8

oh ok well can I get a link to the current assignment? the error might not be correct.


#9

Now that I'm stuck with non-working code, I can't get past it to get the correct link


#10

down in the bottom left corner of the screen there should be an option to select the steps in the lesson


#11


#12

found it - Thanks! too weird how the site determines if the code is correct to let you move forward.


#13

https://www.codecademy.com/en/courses/javascript-beginner-en-Bthev-mskY8/1/5?curriculum_id=506324b3a7dffd00020bf661

I have code that gets to here... working on the next bit.


#14

ya but its really helpful especially when you have large projects.


#15

I just ran your code and there was no problem.


#16

Sadly, I don't know why. It wasn't working and now it is. Same code.


#17

it was most likely a bug but going to an older assignment and back refreshed the page and it ended up working. at least you can move on now :grinning:


#18

Thanks much! .:slight_smile:


#19

ya no problem. good luck with the rest of the course


#20

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