ES6 - Create Strings using Template Literals

Tell us what’s happening:
I am having trouble passing this challenge, I tried to solve it and when I write the code it gives an error but when I copy the solution I can pass it even though they are the same exact code.

  **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 = [];
// Only change code above this line
for (let i = 0; i < arr.length; i++) {
failureItems.push(`<li class="text-warning">${arr.[i]}</li>`); // this is giving an error
failureItems.push(`<li class="text-warning">${arr[i]}</li>`);
}
return failureItems;
}

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

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36

Challenge: ES6 - Create Strings using Template Literals

Link to the challenge:

You should be getting a syntax error message in the console and it should be telling you the exact line the problem is on. You’ve got an extra character where it shouldn’t be.

And why are you doing the same push twice in the for loop?

do you mean Im pushing failureItems twice? If you are it was because I was showing my code and then the one I copy and pasted

And sorry I should have worded the post better, Its not giving me an error but it wont let me pass. I looked back at it again and I don’t see an extra character

Are you still using the exact same code you pasted above? Because the code above is definitely giving me a syntax error:

SyntaxError: unknown: Unexpected token (11:50)

   9 | // Only change code above this line
  10 | for (let i = 0; i < arr.length; i++) {
> 11 | failureItems.push(`<li class="text-warning">${arr.[i]}</li>`); // this is giving an error

And do you see the difference between your line of code and the one you copy/pasted. Look very closely, there is an extra character in yours which is causing the syntax error.

Yeah I got it, didn’t know it had to be that specific but now I know. Thanks

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