Help!

Why does this code not generate a number from 0-1? It prints this---- function Number() { [native code]

heres the code!

document.write(Number)
Number = console.log(Math.random * 1())

Since you’re setting Number equal to a console.log(), you’re effectively creating another function called Number, which means when you write it/log it without calling it (without putting parentheses after it), it prints what it is ([Function: Number]) rather than what it does…


As an aside, Math.random is a function, which means to log the result of calling it, you need the brackets directly after it: Math.random(), and not after the 1

2 Likes

Thank you for the help but could you show me code that would fix my problem?

If all you want to do is document.write the expression Math.random etc, do you really need to store it in a variable and then write that variable?