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

Sev Rob
Sev Rob
3,273 Points

How do I add age in the space for a parameter

I can't figure this ine out. Please help!

script.js
function random_age(1) {
  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

Keegan Usher
PRO
Keegan Usher
Pro Student 26,222 Points

Hello Sev Rob

When wanting to pass a number into a function or any information, you will need to set a parameter for the function when declaring it. So in your case if you want to pass a number into the function for 'age' then set a parameter when declaring the function

function random_age(age) {
  Math.floor(Math.random() * age);
}

Then when calling the function pass in the number you would like age to be equal to.

random_age(1);

This video explains parameters well. https://teamtreehouse.com/library/giving-information-to-functions

Hope this helps,

Keegan

You have to pass the 'age' required value in the call, last line of the js file.

Pass that value directly in the function

          random_age();