I’m trying to understand why this isn’t logging to the console:
let generateTarget = () => {
return Math.floor(Math.Random() * 10);
}
let humanGuess = () => {
return Math.floor(Math.random() * 10);
}
let compGuess = () => {
return Math.floor(Math.random() * 10);
}
console.log(generateTarget(), humanGuess(), compGuess());
Am I not invoking the functions correctly? Thank you
You should be seeing an error in your console that Math.Random
isn’t a function.
1 Like
@ArielLeslie I’m not seeing that error, but I’m using Codepen and it never seems to give me errors, it just doesn’t output anything. Is there something I should use that would give me feedback on what I’ve done wrong?
I also didn’t realize I was using Math.random as a function. I thought it would just return the Math.random value when I invoked the function.
CodePen has a faux console, but you can see the real console by opening the actual browser’s console (hit F12).
Also:
Math.random
is a function. Math.Random
is not.
1 Like
Second line, it’s Math.random()
not Math.Random()
.
1 Like
@ArielLeslie Thanks I fixed that. Can I ask you why, if I put this console.log...
in my function, it doesn’t log?
let generateTarget = () => {
return Math.floor(Math.random() * 10);
console.log(generateTarget());
}
Because your console.log
line is after the return
statement. A return
ends the function execution.
1 Like