Javascript Question on push, unshift in Data Structures lesson

So FCC’s solution to this challenge is to call upon the array with “arr”
as in arr.push or arr.unshift… however in the documentation provided for this lesson,
we are taught we can reference the name of the array to perform .push & .unshift as shown below with the instructor* using romanNumeral.push…

in the lesson, the array is called ‘mixedNumbers’ but we can’t utilize push or unshift as is taught by the description. The solution says to use shorthand… |:

is this indictive of an error or can you call upon arrays as such using their name.?

**should probaly fix for future slow learners like me (’:

let twentyThree = 'XXIII';
let romanNumerals = ['XXI', 'XXII'];

romanNumerals.unshift('XIX', 'XX');

romanNumerals would have the value ['XIX', 'XX', 'XXI', 'XXII'] .

romanNumerals.push(twentyThree);
function mixedNumbers(arr) {
// Only change code below this line
mixedNumbers.push(7,'VIII',9);
mixedNumbers.unshift('I',2,'three');
// Only change code above this line
return arr;
}

console.log(mixedNumbers(['IV', 5, 'six']));
  **Your browser information:**

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

Challenge: Add Items to an Array with push() and unshift()

Link to the challenge:

2022-01-21-11-25-12
:arrow_double_up:Can you send your code using “ask for help”, please? Using this will send us a link to the challenge.:arrow_double_up:

1 Like

oi

Just use .unshift() for 'I', 2, 'three' and .push() for 7, 'VIII', 9.

NOTE:

  1. You must write arr.ushift or arr.push no mixedNumbers.push, etc.
  2. You must use '' no ”„, etc.

ugh… that doesn’t help. /: the challenge isnt difficult to understand.

i am more so seeking someone familiar with JS documentation.

But i very much appreciate your help Stefan. :+1:

Ah… Normally I mustn’t do that…
but

That is solution
function mixedNumbers(arr) {
  // Only change code below this line
  arr.push(7, 'VIII', 9);
  arr.unshift('I', 2, 'three');
  // Only change code above this line
  return arr;
}

console.log(mixedNumbers(['IV', 5, 'six']));

yes… the solution!

however, the solution should be mixedNumbers.push

as is stated in the lesson, see when they use romanNumerals,push?

when you goto use the name of the array (mixedNumbers) to push or unshift, it doesnt work /= it would rather you use shorthand notation or whatever as in “arr”…

arr is the totality of elements that the mixedNumbers have… If you don’t use arr, it is undefined, so mixedNumbers is undefined, so the tests are failing…

1 Like

Ok, so look at what you have here:

function mixedNumbers (arr) {
  // Only change code below this line
  mixedNumbers.push(7,'VIII',9);
  mixedNumbers.unshift('I',2,'three');
  // Only change code above this line
  return arr;
}

console.log(mixedNumbers(['IV', 5, 'six']));

because this:

This isn’t correct. I understand why you’ve written what you’ve written, but you’re misunderstanding a basic thing here – I’ll not expand on that yet, just try to answer these questions:

What type of thing has been given the name mixedNumbers?

and

What type of thing has been given the name arr?

1 Like

So, after tinkering around with the console i found that you can push or unshift with the given titles of created arrays! hooray!!
if only the lesson and the challenge coincided more coherently.
the challenge’s array is made up as a different kind of tree, distinct from the lesson, It certainly throws off eggheads like myself! thank you sm!! :smiley:

1 Like

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