mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2025-12-22 03:26:02 -05:00
2.5 KiB
2.5 KiB
id, title, challengeType, dashedName
| id | title | challengeType | dashedName |
|---|---|---|---|
| 6434750c53db16218f41e6e1 | Step 15 | 0 | step-15 |
--description--
Remember that range() returns an array, so you can chain array methods directly to the function call.
Call range() with 1 and 99 as the arguments, and chain the .forEach() method. Pass the .forEach() method an empty callback which takes number as the parameter.
--hints--
You should call your range() function.
assert.lengthOf(code.match(/range\(/g), 2);
You should pass 1 as the first argument to your range() call.
assert.match(code, /range\(\s*1/);
You should pass 99 as the second argument to your range() call.
assert.match(code, /range\(\s*1\s*,\s*99\s*\)/);
You should chain the .forEach() method to your range() call.
assert.match(code, /range\(\s*1\s*,\s*99\s*\)\.forEach\(/);
You should pass a callback function to .forEach() using arrow syntax.
assert.match(code, /range\(\s*1\s*,\s*99\s*\)\.forEach\(\s*(\([^)]*\)|[^\s()]+)\s*=>/);
Your callback function should have number as the only parameter.
assert.match(code, /range\(\s*1\s*,\s*99\s*\)\.forEach\(\s*(\(\s*number\s*\)|number)\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;
}
const range = (start, end) => Array(end - start + 1).fill(start).map((element, index) => element + index);
const charRange = (start, end) => range(start.charCodeAt(0), end.charCodeAt(0)).map(code => String.fromCharCode(code));
window.onload = () => {
const container = document.getElementById("container");
const createLabel = (name) => {
const label = document.createElement("div");
label.className = "label";
label.textContent = name;
container.appendChild(label);
}
const letters = charRange("A", "J");
letters.forEach(createLabel);
--fcc-editable-region--
--fcc-editable-region--
}