Tell us what’s happening:
Describe your issue in detail here.
Here are the instructions:
Step 16
In your callback, you will need to make two function calls. Start by calling createLabel()
and pass number
as the argument. You should see some numbers appear in your spreadsheet.
Then call the .forEach()
method on your letters
array. Pass an empty callback function which takes a letter
parameter.
Here is my code:
range(1, 99).forEach(number => {
createLabel(number);
letters.forEach((letter) => {});
})
And here is the error message:
Sorry, your code does not pass. Don’t give up.
Your letters.forEach()
callback function should be nested inside the range(1, 99).forEach(number => {}
callback function.
I don’t understand why it says that letters.forEach() should be nested inside range(1, 99).forEach(number => {}) callback function because IT IS already the case.
And tried to type it again and again part by part and I noticed that if I just write letters.forEach() it just says me to add a callback function inside and then if I type letters.forEach(() => {}) it just says to add the letter parameter and when I do it then I get the error message I’ve shared in that post.
To summarize, there is no nesting problem before I write the full expression which is a weird behavior.
Anyone has ever encounterd that problem or have any idea on how to fix it?
Thanks in advance for those who find a solution.
Your code so far
<!-- file: index.html -->
<!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>
/* file: styles.css */
#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;
}
/* file: script.js */
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);
// User Editable Region
range(1, 99).forEach(number => {
createLabel(number);
letters.forEach((letter) => {});
})
// User Editable Region
}
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Challenge Information:
Learn Functional Programming by Building a Spreadsheet - Step 16