You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Forgive me for this rather controversial issue. I love your code... but I think it could be slightly improved by replacing some of your for loops by using more forEach, map or reduce methods.
For example, the code below could be changed to categories.forEach(...)
for(let i = 0; i < categories.length; i++){
let newLine = document.createElement("li");
let parentCrimes = document.querySelector(".categoriesOfCrimes");
parentCrimes.appendChild(newLine);
newLine.setAttribute("class", "crimes");
Here is an example of how we used for Each in a similar scenario:
// Function for creating list items
function listCreation(str) {
var listItem = document.createElement("li");
listItem.textContent = str;
recipeIngredients.appendChild(listItem);
}
// Function to add each ingredient
function addIngredients() {
recipeIngredients.textContent = "";
ingredients.forEach(c => listCreation(c));
}
The text was updated successfully, but these errors were encountered:
Forgive me for this rather controversial issue. I love your code... but I think it could be slightly improved by replacing some of your for loops by using more forEach, map or reduce methods.
For example, the code below could be changed to categories.forEach(...)
for(let i = 0; i < categories.length; i++){
let newLine = document.createElement("li");
let parentCrimes = document.querySelector(".categoriesOfCrimes");
parentCrimes.appendChild(newLine);
newLine.setAttribute("class", "crimes");
Here is an example of how we used for Each in a similar scenario:
// Function for creating list items
function listCreation(str) {
var listItem = document.createElement("li");
listItem.textContent = str;
recipeIngredients.appendChild(listItem);
}
// Function to add each ingredient
function addIngredients() {
recipeIngredients.textContent = "";
ingredients.forEach(c => listCreation(c));
}
The text was updated successfully, but these errors were encountered: