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!

function random_age(1) {
  Math.floor(Math.random() * age);
<!DOCTYPE html>
    <meta charset="utf-8">
    <title>Futuristic MASH</title>
    <link href="normalize.css" rel="stylesheet">
    <link href="style.css" rel="stylesheet">
    <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[]">
      <input type="submit" value="Tell my fortune">

    <script src="script.js"></script>


2 Answers

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

Pass that value directly in the function

Keegan Usher
Keegan Usher
26,226 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.


This video explains parameters well.

Hope this helps,