How to format code?


#1

How to format code?

I am a newbie at JavaScript, (at least “real” Javascript. I took Khan academy’s course a while ago.) and I don’t know how to format this piece of code.
https://www.codecademy.com/courses/learn-javascript/lessons/introduction-to-javascript/exercises/random?action=lesson_resume

Math.floor(Math.random() * 50); I don’t know where to put the semi-colons and parenthesis that this line calls for and I can’t seem to get it right. Please help!


#2

That is all correct, but for the 50 which should be 100.

Math.random() is written like that, with nothing in the argument.

Math.floor(argument) is written like that, and it takes an argument.

In the case above, the argument is Math.random() * 100.

Are these two functions new to you?


#3

I’m sorry, I worded that wrong. I meant to say how do I put the code into a console.log so that it shows up on the screen? I tried every way I could think of and it still wouldn’t work.


#4

console.log(expression);

where expression is the code above (without the semi-colon)


#5

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