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.

function random_age(age) {
  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>


Sorry everyone just figured it out

2 Answers

Zain Sra
Zain Sra
3,236 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

The semicolon goes at the end.

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

This way You floor the random number generated.