Add Items to an Array with push() and unshift() - Help

Tell us what’s happening:
My console.log is I,2,three,IV,5,six,7,VIII,9

But this test fails mixedNumbers(["IV", 5, "six"]) should now return ["I", 2, "three", "IV", 5, "six", 7, "VIII", 9]

What silly thing am I missing?

Your code so far


function mixedNumbers(arr) {
  // change code below this line
    let firstSet = ['I', 2, 'three'];
    let thirdSet = [7, 'VIII', 9];

    arr.unshift(firstSet);
    arr.push(thirdSet);
    
    // change code above this line
    return arr;
}

// do not change code below this line
console.log(mixedNumbers(['IV', 5, 'six']));

Your browser information:

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

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-data-structures/add-items-to-an-array-with-push-and-unshift

Take a closer look at your console log. You’re unshifting/pushing entire arrays into another array, creating an array of arrays.

1 Like

I suggest using console.log(JSON.stringify(...)) so that you can see what @InternetFriend mentions also in the FreeCodeCamp console

Thank you for pointing that out.

Thanks for the hint I am going to try that right now.