My solution for the ES6 String Literals exercise is below. I’ve separated errorClassWarn
and failureItems.push()
into two separate operations.
Though this was a bit of a kludge (and I struggled a little), I’m curious, at this stage of our knowlege, if it is better practice to keep both operations separate for the sake of code readability, or to refactor into one operation, ie:
failureItemes.push(`<li class=“text-warning”>${result.failure[i]}</li>`);
My solution
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
let failureItems = [];
let errorClassWarn = [];
for (let i = 0; i < result.failure.length; i++) {
let errorClassWarn = `<li class="text-warning">${result.failure[i]}</li>`
failureItems.push(errorClassWarn);
// Only change code above this line
};
return failureItems;
}
const failuresList = makeList(result.failure);
console.log(`failuresList: ${failuresList}`);
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 11_1_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36
.
Challenge: Create Strings using Template Literals
Link to the challenge: