Trouble with Create Strings using Template Literals

Trouble with Create Strings using Template Literals

I’m having trouble understanding how to use iterators (E.g., “…arr”) in my solution.

  **Your code so far**

const result = {
success: ["max-length", "no-amd", "prefer-arrow-functions"],
failure: ["no-var", "var-on-top", "linebreak"],
skipped: ["no-extra-semi", "no-dup-keys"]
};
function makeList(arr) {
// Only change code below this line
const failureItems = [`<li class="text-warning">${arr}</li>`];
//console.log(failureItems);
// Only change code above this line

return failureItems;
}

const failuresList = makeList(result.failure);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.114 Safari/537.36.

Challenge: Create Strings using Template Literals

Link to the challenge:

you have created an array that contains one single item

you need to use something that lets you iterate over an array and do something for each element of the array

const result = {
success: ["max-length", "no-amd", "prefer-arrow-functions"],
failure: ["no-var", "var-on-top", "linebreak"],
skipped: ["no-extra-semi", "no-dup-keys"]
};
function makeList(arr) {
// Only change code below this line
const failureItems = [`<li class="text-warning">${arr}</li>`];
//console.log(failureItems);
// Only change code above this line

return failureItems;
}

const failuresList = makeList(result.failure);

the line
const failureItems = [`<li class="text-warning">${arr}</li>`]; is wrong because it will return ["no-var", "var-on-top", "linebreak"]
and the challenge is to return [ '<li class="text-warning">no-var</li>', '<li class="text-warning">var-on-top</li>', '<li class="text-warning">linebreak</li>' ]

The solution i have written is

const result = {
  success: ["max-length", "no-amd", "prefer-arrow-functions"],
  failure: ["no-var", "var-on-top", "linebreak"],
  skipped: ["no-extra-semi", "no-dup-keys"]
};
function makeList(arr) {
  // Only change code below this line
  var failureItems =[];
  arr.forEach((e)=>{

 failureItems.push( `<li class="text-warning">${e}</li>`);

  })

  // Only change code above this line
console.log(failureItems)
  return failureItems;
}

const failuresList = makeList(result.failure);

@DaniyaTheDeveloper I have blurred your code and removed the two fCC solutions you posted. People can use the hint thread if they want to see the solutions.


It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.

You can post solutions that invite discussion (like asking how the solution works, or asking about certain parts of the solution). But please don’t just post your solution for the sake of sharing it.
If you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

ok Thanks For Telling I Was New So I Didn’t Knew It

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.