Build a Linked List - Step 22

Tell us what’s happening:

I just don’t understand why my code is not working. I am getting the message “You should create an else block that assigns current_node.next to self.head”. I thought I had done that. Please help. Thanks.

Your code so far

class LinkedList:
    class Node:
        def __init__(self, element):
            self.element = element
            self.next = None
            
    def __init__(self):
        self.length = 0
        self.head = None

    def is_empty(self):
        return self.length == 0
    
    def add(self, element):
        node = self.Node(element)
        if self.is_empty():
            self.head = node
        else:
            current_node = self.head
            while current_node.next is not None:
                current_node = current_node.next
            current_node.next = node
        self.length += 1

    def remove(self, element):
        previous_node = None
        current_node = self.head
        while current_node is not None and current_node.element != element:
            previous_node = current_node
            current_node = current_node.next
        if current_node is None:
            return        
        elif previous_node is not None:
            previous_node.next = current_node.next
# User Editable Region
        else:
            current_node.next = self.head
# User Editable Region

my_list = LinkedList()
print(my_list.is_empty())

my_list.add(1)
my_list.add(2)
print(my_list.is_empty())
print(my_list.length)

Your browser information:

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

Challenge Information:

Build a Linked List - Step 22

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/workshop-linked-list-class/688ace81e3fb5a95a1f04c55.md at main · freeCodeCamp/freeCodeCamp · GitHub

when you do a = b are you assigning b to a, or assinging a to b?

So it is doing what it is supposed to do - assigns current_node.next to self.head? I cannot move past this step though.

try answering this question, what are you assigning to what when you write a = b?

remember that assignment goes right to left, what is on the right is assigned to the one on the left

OHHH! I think I got it.