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

MOHAMMED AHMED ALNAJAR
PRO
MOHAMMED AHMED ALNAJAR
Pro Student 6,810 Points

I can't understand this function can you help me

can you help me

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

1 Answer

rshap
rshap
12,433 Points

I'm not sure what the HTML file is supposed to do, but the js file takes from the "Math" library the random() function which generates a random float from 0 to 0.999999, times is by the "age" parameter and then uses the floor() function, which rounds the number down. In summery, it creates a number from 0 to the age that you put into it. Although you did forget to return that result. And when you called the function random_age() you didn't put a value into it.

MOHAMMED AHMED ALNAJAR
MOHAMMED AHMED ALNAJAR
Pro Student 6,810 Points

Call the function by giving an age in the space for a parameter.