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

Eliakim Hilkiah
PLUS
Eliakim Hilkiah
Courses Plus Student 4,478 Points

how do i call the function 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. 1 function random_age(70) { 2 Math.floor(Math.random(70) * age) 3 var random_age(70) 4 } 5 random_age(70);

script.js
function random_age(70) {
  Math.floor(Math.random(70) * age)
  var random_age(70)
}
random_age(70);
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>

3 Answers

Rhys Kearns
Rhys Kearns
4,976 Points
function random_age(age) {
// Creating the function random_age and passing the age variable as a parameter
  Math.floor(Math.random() * age)
// Rounding down a random number then timesing by 70 which was passed into the function when i called random_age
}
random_age(70);
Steven Parker
Steven Parker
231,275 Points

The "age" variable declared on the top line isn't being used in this code (and is not needed). The only thing needed for this challenge is to plug in a value for the parameter.

Rhys Kearns
Rhys Kearns
4,976 Points

You are correct Steven thanks for pointing that out! I tunnel visioned and placed it there trying to translate his code over!

Steven Parker
Steven Parker
231,275 Points

It looks like you have called the function correctly on the bottom line. But you also modified the function itself which created the issue. Remove that modification, or start over and leave the provided function as-is.