How do you remove one element of an array each time a while loop runs?


#1
let thingsToDo = ['do laundry', 'take out the garbage', 'make dinner', 'walk the dog', 'go to the bank'];

for (let thingsToDoIndex = thingsToDo.length - 1; thingsToDoIndex >= 0; thingsToDoIndex++) {
  console.log('I need to ' + thingsToDo[thingsToDoIndex] + '.');
}

while (thingsToDo.length > 3) {
   console.log('I have too many things to do!');
thingsToDo.pop('do laundry')
 }

infinite loops

Instruction I am stuck on:
On line 9, use an array method to remove an element from the thingsToDo array each time the block executes.

I do not know how to use a .pop method with an array

thingsToDo.push('go to the bank');

#2

The Array.pop() method does not take an argument. It always removes the last element of the array.


#3

What should I use? I am totally unsure and there are a wide variety of resources. I typically don’t ask, but I was hoping for a recommendation or method.


#4

I love to learn how to actually do the methods, but at some point I need to move on too…


#5

Moving on is not an option if you are still having problems. Stick with the subject until you master it. There is no gun to our head to complete the lessons in a specified amount of time. Take your time and put in the work. There is no career waiting for us at the end of these courses… They are introductions, only. The real work is still out in front of us.


#6

Did you check the hint?


#7

the instructions say that .pop can be used to remove an array item


#8

Then that is the one to use. pop() removes the last item, .shift() removes the first. It matters not which you use for this lesson.


#9
thingsToDo.pop([---])

Is that the correct syntax?


#10

No. There should be no argument.


#11

I was able to critically think and figure it out!:grin:


#12

No course can take the place of documentation. The MDN link above should be at the top of your bookmarks. If you are not referring to the documentation, then you are going to find learning hard. It’s tough enough already given all the new concepts and syntax, don’t make it harder by expecting things to just stick to you. They won’t. Every new concept, keyword or construct needs to be studied thoroughly, and we need lots of practice.


#13

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