Files

2.8 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
642dccb78549c9285835ebc2 Step 2 0 step-2

--description--

Functions are ideal for reusable logic. When a function itself needs to reuse logic, you can declare a nested function to handle that logic. Here is an example of a nested function:

const outer = () => {
  const inner = () => {

  };
};

Declare a nested createLabel function using arrow syntax. It should take a name parameter.

--hints--

You should declare a createLabel variable in your onload function.

assert.match(code, /window\.onload\s*=\s*\(\s*\)\s*=>\s*\{\s*(?:const\s+container\s*=\s*document\.getElementById\(\s*('|"|`)container\1\s*\)\s*;?)?\s*(?:let|var|const)\s+createLabel/);

Your createLabel variable should be declared after your container variable.

assert.match(code, /window\.onload\s*=\s*\(\s*\)\s*=>\s*\{\s*const\s+container\s*=\s*document\.getElementById\(\s*('|"|`)container\1\s*\)\s*;?\s*(?:let|var|const)\s+createLabel/);

Your createLabel variable should be declared with const.

assert.match(code, /window\.onload\s*=\s*\(\s*\)\s*=>\s*\{\s*const\s+container\s*=\s*document\.getElementById\(\s*('|"|`)container\1\s*\)\s*;?\s*const\s+createLabel/);

Your createLabel variable should be an arrow function.

assert.match(code, /window\.onload\s*=\s*\(\s*\)\s*=>\s*\{\s*const\s+container\s*=\s*document\.getElementById\(\s*('|"|`)container\1\s*\)\s*;?\s*const\s+createLabel\s*=\s*(\(.*\)|[^\s()]+)\s*=>/);

Your createLabel function should have a name parameter.

assert.match(code, /window\.onload\s*=\s*\(\s*\)\s*=>\s*\{\s*const\s+container\s*=\s*document\.getElementById\(\s*('|"|`)container\1\s*\)\s*;?\s*const\s+createLabel\s*=\s*(\(\s*name\s*\)|name)\s*=>/);

Your createLabel function should be empty.

assert.match(code, /window\.onload\s*=\s*\(\s*\)\s*=>\s*\{\s*const\s+container\s*=\s*document\.getElementById\(\s*('|"|`)container\1\s*\)\s*;?\s*const\s+createLabel\s*=\s*(\(\s*name\s*\)|name)\s*=>\s*\{\s*\}/);

--seed--

--seed-contents--

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <link rel="stylesheet" href="./styles.css" />
    <title>Functional Programming Spreadsheet</title>
  </head>
  <body>
    <div id="container">
      <div></div>
    </div>
    <script src="./script.js"></script>
  </body>
</html>
#container {
  display: grid;
  grid-template-columns: 50px repeat(10, 200px);
  grid-template-rows: repeat(11, 30px);
}

.label {
  background-color: lightgray;
  text-align: center;
  vertical-align: middle;
  line-height: 30px;
}
--fcc-editable-region--
window.onload = () => {
  const container = document.getElementById("container");

}
--fcc-editable-region--