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 trial

JavaScript Treehouse Club - MASH MASH - JavaScript The Structure of Functions - Part 3 of 3

SISLEY NGUYEN
SISLEY NGUYEN
1,835 Points

Call the function by giving an age in the space for a parameter.

Call the function by giving an age in the space for a parameter.

script.js
function random_age(age) { // new function called random_age that taks one parameter)
  Math.floor(Math.random() * age);
}
random_age();
index.html
<!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>

2 Answers

Sean T. Unwin
Sean T. Unwin
28,690 Points

On line 4 of script.js insert a number between the brackets of random_age();.

:-)

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,252 Points

Hi there,

You're very close. :-)

function random_age(age) { // new function called random_age that taks one parameter)
  Math.floor(Math.random() * age);
}
random_age();

What's happening is you've written a function that contains a parameter called age, that's the thing in between the parentheses. You've written a function which is a piece of organised code that does something. But just writing the function on it's own won't do the job.

To get the function to perform the action you have to write something called a function call.

random_age(6);

This is basically just the function name on it's own. However you can pass values into it. This function takes one parameter which is waiting for a value. So the value in this case is what replaces the age parameter. I used 6 for this example.

Hope this makes sense :)