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

Daniel Hildreth
Daniel Hildreth
16,170 Points

Need help on "Giving Information to Functions" course.

I have a question about one of the challenges in the "Giving Information to Functions" course in Treehouse. I have watched the video a few times and seem to understand the teachers' examples, but when I get to the challenge I can't seem to get it right. One of the questions looks like this:

Complete the code below to call the function and pass the value 12 to it:

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

I tried inputting "return Random," "return getRandom(12)," "return Random(12)," "getRandom(12)," "console.log getRandom(12)." What am I doing wrong? Can someone help me with this and explain why I'm wrong and such?

5 Answers

Hi Daniel,

When you're only calling a function, you only use the function name, a set of parenthesis, and any value(s) you are going to place into it like so:

getRandom(12);
Daniel Hildreth
Daniel Hildreth
16,170 Points

Marcus I have done this answer as well.

I just used it for the quiz, and it is the correct answer.

As my code above also.

No, Daniel Newman, your code is not correct, because the quiz does not ask you to call console.log().

Daniel Hildreth, the quiz already has a semi-colon at the end so in the quiz, you just use: getRandom(12).

Here is proof that it is correct:

quiz correct answer

And here is proof that you can't use console.log() in the quiz question:

quiz incorrect answer

Daniel Hildreth
Daniel Hildreth
16,170 Points

Yes Daniel I think I have tried it that way. I'll double check on that though.

EDITED: Yes Daniel I have tried that as the answer and it says it's wrong.

Have you try yo do this way?

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

console.log(getRandom(12));

It works perfect. In your code there is no () bracket after log method of console. console.log(parameter) is right way to treat a function or Object methods.

Daniel Hildreth
Daniel Hildreth
16,170 Points

Weird cuz I know I've tried that; maybe I had an extra parenthesis.

Just retake the quiz, and you'll see that I'm steering you in the right direction, Daniel.

Daniel Hildreth
Daniel Hildreth
16,170 Points

Yep I got it, I think I did put in an extra parenthesis. Thank you!

You're welcome, Daniel. If you want to go ahead and mark a best answer, this can be shown to be resolved. Happy Coding!