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 2 of 3

Is it just me or is there a bug? I put the semicolon right after Math.Floor then the error tells me to do just that.

I put a semi colon after 'Math floor' and the error told me to do the same thing.

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

Sorry everyone just figured it out

2 Answers

Hey Frank,

You put ";" at the wrong place.

Correct Solution would be this :

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

floor() is a function that belongs to Math object/class and you put ";" semicolon at the end of an expression, function or line of code.

Math.floor () contains another function call to Math.random()

When looking at functions , always go from inside to outside. See what's inside the inner most parentheses and then move back step by step.

At first it calls ,

Math.random() to generate a random number

then it multiply that random number with age

and finally it calls Math.floor() on the result of that mutiplication

floor means lowerbound on a value i.e Math.floor(2.8) would give us 2 because it works opposite to rounding off to next highest decimal value.

I hope it answers your question , Happy Coding :)

  • Zain

The semicolon goes at the end.

Math.floor(Math.random() * age));

This way You floor the random number generated.