Unit 6 lesson 2-removeItem

Hi everyone,

I am new to code.org and am using for the 1st time to teach a lesson. I am using unit 6-lists and am working through the lesson on my own. I am in lesson 2 where it talks about removing items from the list. In the code editor, it is not recognizing removeItem. This is how I am typing the code removeItem(classList, 0). I get an error==removeItem is not a function. I noticed that it also does not work for appendItem or insertItem.

What am I doing wrong?

Hmm, off the top of my head I’m not seeing a problem with that section. Have you tried pulling the block of it and making sure the syntax matches what you are writing? If you are still having trouble, remix the level and share it here. We’ll take a look and see if we can pinpoint where the error may be rooted.

1 Like

Hello @cwojcik5,

I’m not too sure of what your issue may be given that we can not see the full context of what lead up to this particular issue, however perhaps a simple example may help you debug your code

var items = [1, 2, 3, 4, 5];

removeItem(items, 0); // or you can do items.splice(0, 1) // (<index>, <amount>)

console.log(items); // 2, 3, 4, 5

as you can see this should work without issues, your student could have also defined removeItem as a variable as the console no longer recognizes it as a function

if you need further help do link the project so that either me or someone else can further diagnose your error

Varrience

In Notepad++, i dont get the option of removeItem, appendItem or insertItem. I have tried the other options listed but none work.

I dont get the option of removeItem, appendItem or insertItem in Notepad++.

Javascript doesn’t actually have removeItem, appendItem and insertItem functions. So trying to call those in Notepad++ won’t work.

Here is a site that lists methods that you could call in Notepad++:

For example, if you want to add an item to a list it would be:
myNumbers.push(10);

As @sgaraas says that function will not be available in Notepad++ this function has been implemented by CDO therefore if you really wish to continue using removeItem you will need to implement a pollyfill that will satisfy the JS interpreter as I’ve said before in my example if you read it Array.prototype.splice is a valid method in JS that is more versatile and can remove more items in a list than removeItem

function removeItem(array, position) {
 return array.splice(position, 1)
}

of which i find this one line function useless since it’s just a recase of a already prototype function that can be applied more effectively, moreover you didn’t specify what editor you were using before that would have been more helpful in determining my reply earlier

Varrience