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

Frank Formica
Frank Formica
3,595 Points

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>
Frank Formica
Frank Formica
3,595 Points

Sorry everyone just figured it out

2 Answers

Zain Sra
Zain Sra
3,232 Points

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
Dvontre Coleman
Dvontre Coleman
13,075 Points

The semicolon goes at the end.

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

This way You floor the random number generated.