There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
How would I have called the 3rd character instead of the 3rd item in the list?
const famousSayings = ['Fortune favors the brave.', 'A joke is a very serious thing.', 'Where there is love there is life.'];
console.log(famousSayings[2]);
If you want to access multiple consecutive items you can use slice or splice. I assume this course will go over both of these. These both return arrays.
It’s odd that the ’ isn’t counted. You would think anything after the = would be counted as some sort of index. My first thought was that it was, then I was going to ask why it wasn’t [7] but this clears that up.
That shouldn’t be a problem. Most developers prefer leaving no space between the array and the square brackets. However, there won’t be an error if you do
This does appear to be a bug. Since arrays in JS are zero-indexed, printing the first element would be done with ‘0’ in the brackets; the second element using [1]; and the third element using [2].
For some reason, the exercise requires you to input [3], which results in an undefined message but marks the exercise correct.
it is not a bug, but the intention of the author to demonstrate what happens when we attempt to access an element that does not exist. The index is said to be out of range.
hello ,
could someone help me please ? i am reading about arrays and thought something which i am not very clear . It is about Method of .push and .pop. As you can see in the example, when we want to add new element ‘pear’ , it calls variable directly cart.push(‘pear’); whereas for .pop, they call the new variable name ‘const poppedIngredient = Ingredients.pop(); ’ . My question is ’ do we need to call new variable name ‘poppedingredient’ ? Can we not simply say ingredients.pop(); ? Vice versa, in .push method, can we call new variable name like ‘pushedCart’=cart.push(pear);’ ?