Why is this function arg undefined?

So I’m building a to-do list, and trying to add on extras and stuff and I have a problem. I’m trying to pass an unordered list that I’ve declared through the list arg of this function(I’ve cut off an unrelated portion of the function). When I try to run this function in the browser, the console says that list is undefined in that line(at list.children). But it shows the expected value of list in the console.log below it. Can someone tell me what’s going on?

EDIT: I’ve added more of the function because it’s needed, and I have more info. The idea of all of this(I’m sure it’s way more complex than needed, but I’m learning) is that when I hit the save button, I want the removeMovie function to compare the unordered list of movies with the array of movies, and if a movie has been deleted from the list, then remove it from the array. If I save without deleting any items, the function runs normally, and console.log logs both of my lists. But if I delete an item and then try to save, that’s when the error occurrs.

function saveFunk() {
	//Remove deleted movies
	removeMovie(listDanny, dannyArray);
	removeMovie(listLola, lolaArray);

	localStorage.setItem('dannyMovies', JSON.stringify(dannyArray));
	localStorage.setItem('lolaMovies', JSON.stringify(lolaArray));

}

function removeMovie(list, arr) {
	let textContentArray = Array.from(list.children).map(node => node.firstChild.textContent);
	console.log(list);
	
	for(let i=0; i < arr.length; i++) {
		if(textContentArray.indexOf(arr[i]) === -1) {
			arr.splice(i, 1);
			removeMovie();
		}
	}
}

Is it saying that list is undefined or that list.children is undefined?
What is the structure of list?

It’s saying TypeError: list is undefined

The list is the unordered list, that to-do items get added to: ul id=“listDanny” class=“list”

For what it’s worth I’ve added some lines (redeclaring the variables, and the return statement. not the local storage strings) and it’s working better now. But still not 100%. From what I can gather it has something to do when I delete an item from only one list and save, the other list is what comes back as undefined(sometimes).

function saveFunk() {
	//Remove deleted movies
	`dannyArray =` removeMovie(listDanny, dannyArray);
	`lolaArray =` removeMovie(listLola, lolaArray);

		localStorage.setItem('dannyMovies', JSON.stringify(dannyArray));
		localStorage.setItem('lolaMovies', JSON.stringify(lolaArray));

}

function removeMovie(list, arr) {
	let textContentArray = Array.from(list.children).map(node => node.firstChild.textContent);
	console.log(textContentArray);
	console.log(list);


	for(let i=0; i < arr.length; i++) {
		if(textContentArray.indexOf(arr[i]) === -1) {
			arr.splice(i, 1);
			removeMovie();
		}
	} `return arr;`
}

removeMovie();
This line is recursively calling the removeMovie function without any parameters, so list is in fact undefined.

Ahhhhhh, yes! That’s it, thank you! Duh, it’s so clear now. Ok, now through this whole ordeal I’ve already seen other things I need to fix. Thanks :smiley:

I’m glad I could help. Happy coding!