Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDaniel Hildreth
16,170 PointsNeed 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
Marcus Parsons
15,719 PointsHi 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
16,170 PointsYes 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.
Daniel Newman
Courses Plus Student 10,715 PointsHave 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
16,170 PointsWeird cuz I know I've tried that; maybe I had an extra parenthesis.
Marcus Parsons
15,719 PointsJust retake the quiz, and you'll see that I'm steering you in the right direction, Daniel.
Daniel Hildreth
16,170 PointsYep I got it, I think I did put in an extra parenthesis. Thank you!
Marcus Parsons
15,719 PointsYou're welcome, Daniel. If you want to go ahead and mark a best answer, this can be shown to be resolved. Happy Coding!
Daniel Hildreth
16,170 PointsDaniel Hildreth
16,170 PointsMarcus I have done this answer as well.
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsI just used it for the quiz, and it is the correct answer.
Daniel Newman
Courses Plus Student 10,715 PointsDaniel Newman
Courses Plus Student 10,715 PointsAs my code above also.
Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsNo, 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)
.Marcus Parsons
15,719 PointsMarcus Parsons
15,719 PointsHere is proof that it is correct:
And here is proof that you can't use console.log() in the quiz question: