Why is printing 3 times

Tell us what’s happening:

resultDisplayArray

should be an array containing

result failure

messages.

resultDisplayArray

should be equal to the specified output. Template strings and expression interpolation should be used. An iterator should be used. // tests completed // console output [ ‘

  • no-var
  • ’, ‘
  • var-on-top
  • ’, ‘
  • linebreak
  • ’ ] [ ‘
  • no-var
  • ’, ‘
  • var-on-top
  • ’, ‘
  • linebreak
  • ’ ] [ ‘
  • no-var
  • ’, ‘
  • var-on-top
  • ’, ‘
  • linebreak
  • ’ ]

    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
    const resultDisplayArray = `[
    '<li class="text-warning">${arr[0]}</li>',
    '<li class="text-warning">${arr[1]}</li>',
    '<li class="text-warning">${arr[2]}</li>'
    ]`;
    // Only change code above this line
    console.log(resultDisplayArray);
    return resultDisplayArray;
    }
    
    const resultDisplayArray = makeList(result.failure);
    
    

    Your browser information:

    User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36.

    Challenge: Create Strings using Template Literals

    Link to the challenge:

    Hello~!

    You see the array print thrice in the console because you have a console.log(resultDisplayArray) in your function. This prints when the function is called, which occurs three times.

    1. You have a function call makeList(result.failure) at the bottom of your code.
    2. The resultDisplayArray should be an array containing result failure messages. test calls the function.
    3. The resultDisplayArray should be equal to the specified output. test calls the function.

    Three function calls resulting in three console.log runs :slight_smile:

    you’re right but why didn’t they make it like
    const aNewName = makeList(result.failure);

    i dont even see the third?

    I believe to demonstrate variable scoping. :thinking:

    The third function call? There are two in the tests, and one in your code.

    1 Like