JavaScript JavaScript Basics Creating Reusable Code with Functions Review: Giving Information to Functions

Piotr Połaniecki
PRO
Piotr Połaniecki
Pro Student 3,181 Points

What am I doing wrong?

In a quiz I had to finish a code:

function getRandom( upper ) { return Math.floor(Math.random() * upper) + 1; } ;

to call the function and pass an argument (12) to it. So I did it in this way:

getRandom (12);

It's wrong. Why? Please light me up...

5 Answers

Bogdan Cabaj
Bogdan Cabaj
15,802 Points

You have a space between getRandom and (12) . Should be getRandom(12) ???

changed from comment to answer

Piotr Połaniecki ,

I selected "best answer" for you.

Bogdan Cabaj
Bogdan Cabaj
15,802 Points

You are including a semicolon in the text box where a semicolon is already included at the end. The only thing you need is getRandom(12).

Piotr Połaniecki
PRO
Piotr Połaniecki
Pro Student 3,181 Points

Thanks,

I already erased "my" semicolon and it still does not work...

Yeah, it looks like the quiz is not allowing a space there but it would be fine on a real project.

Piotr Połaniecki
Piotr Połaniecki
Pro Student 3,181 Points

Hi Bogdan, please rewrite your comment as an answer so I can give you "best answer". Cheers.

Piotr Połaniecki
PRO
Piotr Połaniecki
Pro Student 3,181 Points

Thanks guys,

You're right although it's strange because in previous videos Dave have used spaces. I compared my work with his work in Workspaces and everything was fine. Never mind, I passed the quiz anyway, I was just curious. Wish you all the best. Piotr

Abdi Nur
Abdi Nur
3,802 Points

just completed this quiz, seems getRandom(12); worked for me.

all the best.