My code works but it's not accepted

Tell us what’s happening:
Hello i used array mutation instead of pushing into an empty array and my code works but is not admited am i wrong in something?

Your code so far


const result = {
success: ["max-length", "no-amd", "prefer-arrow-functions"],
failure: ["no-var", "var-on-top", "linebreak"],
skipped: ["id-blacklist", "no-dup-keys"]
};
function makeList(arr) {
"use strict";

// Only change code below this line
let n = 0;
  do {
  arr[n] = `<li class="text-warning">${arr[n]}</li>`;
  n++;
} while(n < arr.length );
const resultDisplayArray = arr;
// Only change code above this line

return resultDisplayArray;
}

const resultDisplayArray = makeList(result.failure);
console.log(resultDisplayArray);

Your browser information:

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

Challenge: Create Strings using Template Literals

Link to the challenge:


Hello!

It seems your code is not passing because you are mutating the original array (result.failure). When I adjusted your code to only read that array and not mutate it, the code passed.

1 Like

Thank you, i just thought that there is no problem in mutating the original array since there is no condition saying so

It looks like the test script tries to map the result.failure values and compare them to the expected output - so when you mutate the original array, it causes that test to fail as it does not match.