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 trialJodia Steenkamp
Front End Web Development Techdegree Student 1,378 PointsHow do you "Call the function by giving an age in the space for a parameter."?
I added the parameter within the parenthesis but I'm sure what is meant by "Calling the function by giving an age in the space for a parameter."
function random_age(age) {
Math.floor(Math.random() * age);
}
random_age();
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Futuristic MASH</title>
<link href="normalize.css" rel="stylesheet">
<link href="style.css" rel="stylesheet">
</head>
<body>
<h1 class="logo"><img src="img/mash-logo.svg" /></h1>
<p class="instructions">Fill in the blanks and your future will be foretold.</p>
<form action="" method="post" id="mash">
<div class="choice-bucket">
<h4 class="highlight">What's your future pet?</h4>
<input name="pet[]">
<input name="pet[]">
<input name="pet[]">
<input name="pet[]">
</div>
<input type="submit" value="Tell my fortune">
</form>
<script src="script.js"></script>
</body>
</html>
5 Answers
Jennifer Nordell
Treehouse TeacherHi there! Your very bottom line is the call to the function. But you need to tell it what age to send! You could do something like this:
random_age(90);
Hope this helps!
Alexander Davison
65,469 PointsLet's say we had this function:
function sayHelloTo(person) {
console.log("Hello, " + person + "! Nice to meet you!");
}
And I called the function like this:
sayHelloTo();
It would cause an error. This is because our sayHelloTo function was expecting a parameter, which in this case is person. So, to make this work, let's pass in a parameter (or, another way to say it is "Calling the function by giving an age in the space for a parameter").
sayHelloTo("Jodia");
This is now fixed. The output of this is:
Hello, Jodia! Nice to meet you!
So, now do you get a clue of what the challenge meant about "Calling the function by giving an age in the space for a parameter"?
Good luck, Alex
Alexander Davison
65,469 PointsOh man, it took a while to type out my answer that's why it took so long (and while I was typing Jennifer Nordell answered ). I still like your answer Jennifer Nordell so I'll give you a upvote :)
~Alex
Jodia Steenkamp
Front End Web Development Techdegree Student 1,378 PointsThanks :) I eventually tried and tried until I got it right (urgh!)
What is the reason for the 'call to function' being out of the relevant function? Should it not be within the curly brackets?
Jennifer Nordell
Treehouse TeacherNo, it shouldn't. The code inside the curly braces is the code we want to run every time we call/invoke/execute the function. That call (last line) there tells the browser "Ok now run/execute this code I've defined.." And the thing in the parentheses is the information we're passing to that code. Hope that makes sense!
Alexander Davison
65,469 PointsI like that simple answer :)
~Alex
Alexander Davison
65,469 PointsYou might find this Treehouse video helpful about functions.
Hope it helps! ~Alex
Jodia Steenkamp
Front End Web Development Techdegree Student 1,378 PointsGreat stuff, thanks Jen and Alex for the help. I understand now :) Whether that intel remains, I'm still to find out. Cheers :)
Alexander Davison
65,469 Points:) when first learning programming, function are the most confusing thing ever. LOL but I'm suprised how fast you got the hang of it (when I was learning functions it took a couple days to understand how it works because at that time I wasn't using Treehouse I was reading books about programming, and there was no community for books, of course so I can't ask questions except for asking my father , who also knows programming)