This forum is now read-only. Please use our new forums! Go to forums

0 points
Submitted by Chong Wang
over 10 years

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!

Answer 51ff5f2f80ff33134b005775

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.

points
Submitted by haxor789
over 10 years

1 comments

Chong Wang over 10 years

@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.

Answer 51ff711b548c359e2f005d64

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.

points
Submitted by haxor789
over 10 years

1 comments

Chong Wang over 10 years

@haxor789:I got it.Thanks,sir!