Since when can variables be swapped for other variables which have already been declared?

In this code, to begin with, the object has already been declared as ‘const result’. But then the function takes the argument, arr in the block:

function makeList(arr) {
“use strict”;
// change code below this line
const failureItems = ;
for (let i = 0; i < arr.length; i++) {
failureItems.push(<li class="text-warning">${arr[i]}</li>);
}

So my question is at what point does this code block refer to the object ‘const result’?

If concepts like this has not been earlier introduced before their sudden appearance in future tasks, like in a lot of the freecodecamp tasks, it should be because it does not help a beginner.


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

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

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

Challenge: Create Strings using Template Literals

Link to the challenge:

Can you rephrase the question? It’s not really clear to me what you are trying to ask.

Anyway result is just an object, and one of its values is passed to the makeList function here

const failuresList = makeList(result.failure);

As @Marmiz pointed out, the variable result is used in the following line near the end of the code block:

const failuresList = makeList(result.failure);

result.failure is an array that gets passed to the function makeList, which then is iterated over to create the failureItems array that gets returned by the function.

Not sure what concept you feel appears here that has not already been introduced before. Could you elaborate a bit more on the concept you believe has been suddenly introduced?

This lesson could be rewritten without using the object, but it does not change how the function would be written. It would also not change the main concept being taught, which is using Template Literals.

const failures =  ["no-var", "var-on-top", "linebreak"];

function makeList(arr) {
  "use strict";
  // change code below this line
  const failureItems = [];
  for (let i = 0; i < arr.length; i++) {
    failureItems.push(`<li class="text-warning">${arr[i]}</li>`);
  }
  // change code above this line
  return failureItems;
}

const failuresList = makeList(failures);
console.log(failuresList)

I looked for the ‘result’ after that block in the code and could not find it. I must have deleted it during editing by mistake. If I was more patient I would see it. It’s just a build up of seeing concepts not introduced and being expected to knOW them in earlier tasks that made me impatient. Thanks for pointing it out.

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