Paper, rock, scissors... (3/9) M for Math causing problem! stuck!


#1



Hi, I get the message :
"Oops, try again. Did you set var computerChoice = Math.random() ? The capital 'M' in 'Math' is important!"
But i am already in capital M ?!?!? i've tried to put it in small then back to big, add some spaces around, not, then some other post talk about refreshing, so ive refreshed (dozen times), closed the page, logged off, do a magic dance and prayed to the gods of nonsense... and im still stuck.
The code is working but because i get the error message that M should be in capital i cant progress !
(here goes my attempt at understand the wizardry of computer ! )

please help !!!!


var userChoice = prompt( "Do you choose rock, paper or scissors?")
console.log("User Choice: " + userChoice);    
var computerChoice =Math.random(); {
    if (computerChoice<0.34) {
     computerChoice= "rock";
    }
    else if  (computerChoice>0.67) {
    computerChoice= "paper";
    }
    else { 
    computerChoice= "scissors";
    }
}
console.log("Computer Choice: " + computerChoice);


#2

It asks you to assign the result of calling Math.random to your variable.
You are doing that.
But then you overwrite it, undoing what you just did.


#3

hooo... so nothing to do with the unfamous M !?!?!
err.. ok .
then could you may be correct me , please?
(only started 2 days ago and now im really lost ! :sweat: )
thx for advise.


#4

Looks like you did more than the instructions ask for. Those extra actions overwrite the variable that is supposed to contain the result of Math.random as mentioned above.

Problem: doing extra things that undo what should be done
Solution: remove the extra stuff that isn't asked for

Sidenote:

this:

var computerChoice =Math.random(); {
    if (computerChoice<0.34) {
     computerChoice= "rock";
    }
    else if  (computerChoice>0.67) {
    computerChoice= "paper";
    }
    else { 
    computerChoice= "scissors";
    }
}

Is formatted as if computerChoice is a function, with a function body. It's not. It should be written this way:

var computerChoice = Math.random();
if (computerChoice < 0.34) {
    computerChoice = "rock";
}
else if (computerChoice > 0.67) {
    computerChoice = "paper";
}
else {
    computerChoice = "scissors";
}

#5

hi ionatan,
first of all thanx for support. im on my own, self teaching so no references other then what already been done by others...
i would have thought that the first IF being part of the computer random choice would have to be in the { } as part of the variable.
but even if i take them off, or try you copy/paste your writing insert in mine, or altogether take all of and just copy/paste yours... im still getting that read massage error:

i mean the all thing works (whenever i leave the { } or not), i get the prompt and my choice and the random choice of the computer get written.... but that message always appear!
and since i dont get a green tick and cant proceed to the next stage ! :confused:

thanx for help again.


#6

Hello jojosuperstar
I also got that message. You did everything right.The problem is that you did steps earlier.
Where you are right now should only have these codes.

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


#7

hi zur9, thanx for assistance... i need that !

so i copied/pasted what you stated above exactly and got :

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

so i added the log and get a formula:

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

and got the same error message, so i took the userChoice prompt since it didn't seems to be part of that script at the moment, and still get the same message!

var computerChoice = Math.random();
console.log("Computer Choice: " + computerChoice);

so i went back to the previous page, (lesson 2.user choice) click run and save, proceed to next stage (lesson3. computer choice: part1)
....and inserted the part with the Math.random and the log

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

and i STILL get the message of the log missing !
i honestly feel despair now, started the course 4 days ago with all the enthusiasm possible and been stuck for the past 2 with that ! absolutely gutted !

thanx again for any assistance .


#8

I didn't post anything for you to copy, I reformatted your own code. My suggestion for passing the exercise was something else.

Read the instructions and do only what they say, nothing more or less.


#9

Hi jojosuperstar
You are still doing things too fast, the code below is also right.But you did an extra step which makes the lesson unable to complete.

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

the [ "Computer Choice:" +] isnt included.

Follow the steps that they ask you ,read carefully.


#10

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