This forum is now read-only. Please use our new forums at discuss.codecademy.com.

1111 points
595d0f025821223dca00026e_509339479
Submitted by
Chong Wang
over 5 years ago

A newbie question?HELP!

Instructions is:1.Under your previous code, declare a variable called computerChoice and make it equal to Math.random().
2.Print out computerChoice so you can see how Math.random() works. This step isn't needed for the game - just useful for learning!
my code is:var userChoice = prompt("Do you choose rock,paper or scissors?");
var computerChoice = Math.random();
console.log = (computerChoice);
I hit Save&Submit code,But,But it says:“Oops, try again! Did you remember to log computerChoice to the console?”
Thus,I am very confused,HELP!


1 vote

permalink

you need to use console.log(computerChoice).
console.log= (computerChoice) would overwrite the log property of console with the value of computerChoice instead of showing it in the console.

3324 points
5139256f6a90a0ef75009600_690502710
Submitted by
haxor789
over 5 years ago

1 Comment

595d0f025821223dca00026e_509339479 Chong Wang over 5 years ago

@haxor789:Thanks,sir.I tried as you say,It runs well,But I have a new confuse, as you say what should I distinguish "console.log()" with "console.log = ()".Or it's just difference in the special codecademy "game",Please.


0 votes

permalink

Well as far as I can see from the track, you should know about functions already, do you? Well console.log is a function, well actually only log is the function and console the structure which contains it but lets not bother about this yet, you'll get to know objects in a later course. So as all other functions you call it by appeding () with the parameters inside. What

console.log = ()

does is that it overwrites the variable. e.g.

var print;
print = function(para){
console.log(para);
}
print("test"); //--> test
print = 42;
print()// --> error print is not a function
console.log(print)//--> 42

So to say you change the value of the variable from a function to the string you wanted to print and this behavior is not limited to codecademy or this game.

3324 points
5139256f6a90a0ef75009600_690502710
Submitted by
haxor789
over 5 years ago

1 Comment

595d0f025821223dca00026e_509339479 Chong Wang over 5 years ago

@haxor789:I got it.Thanks,sir!