Computer Choice: Part 2


#1

What am I doing wrong?


#2

You probably missed semilicon at the end of second line.


#3

You're missing a set of { } around the entire if/elseif/else statement, at least that's how I did it and that appears to be the only difference, aside from it goes "rock", "scissors", "paper".

I'm pretty sure you need the entire complex in a set of { } (I don't know what they're referred to in programming; this is my first time trying any of this) because the sequence is linked to the fx of the computer choice. I might be wrong but if you're still stuck try it out and see if it helps.

Let me know too. Helps me know if I'm learning this right or not.


#4

I've been messing with this step for awhile and can't seem to get this code to work. I've read the other parts of the thread and can't seem to figure out what's wrong. Help please?

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

if (computorChoice <= .33){
computorChoice = "rock";
}
else (computorChoice <= .66){
computorChoice = "scissor";
}
else {
computerChoice = "paper";
}


#5

Check your Spellings for starters. You have made a function named computorChoice. But in console.log you have written computerChoice.
Secondly, there will be no semi-colon(; ) in line 2 (i.e: Math,random() )


#6

Your right about the spelling error. But the semicolon after Math.random() is correct. Still I can't see what is wrong about @crlevine 's code. Have you tried refreshing the page? Also could you post your code as code so that one could run tests on it?

PS: @byteninja02285 From what I can see the {} are correct you don't need to wrap the whole if/else if/else statement in {} or what do you mean specifically. Btw they are called blocks of code because they wrap many statements to one.


#7

I tried adding a semicolon; it still doesn't run. I think the first three lines are correct, because they ran for the first part where the computer selects a random number.


#8

What kind of error do you get?


#9

As said from what I can see this code should be correct maybe post you code copyable so that one can run it. Or as said as stupid as it sounds, refresh the page and run it again. Often stuff gets stuck in the memory and refreshing the page resets the JS which might solve the problem. In case it is not provide your code and the error message.


#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

It says "system error. missing before statement" (I think maybe a space of some kind).


#12

ok here you have a condition after else which should not be there but which had not be there in your screenshot. Also whitespaces (SPACE,TAB,LINEBREAK, aso) are not a problem as the interpreter just reads it something like this:

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

Meaning they are simply ignored and only there to make the code human readable.


#13

Ok, so I deleted (computerChoice < 1.0) and now it runs. I ran it before without it, and it didn't work then. The only difference from the original I see now is I switched it from <= to just <.

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


#14

As said I can't see why the original shouldn't pass but glad that it is working now.


#17

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