Build a Salary Tracker - Step 31

Tell us what’s happening:

why can’t I pass this step? It keeps telling me, “You should have a third if statement inside your level setter.” I checked everything in my code but still no idea. I noticed that there seemed like to have the same problem just like me but they didn’t help me. Could somebody give me an answer plz? Thanks a million

Your code so far

class Employee:
    _base_salaries = {
        'trainee': 1000,
        'junior': 2000,
        'mid-level': 3000,
        'senior': 4000,
    }

    def __init__(self, name, level):
        self.name = name
        self.level = level
        self._salary = Employee._base_salaries[level]

    def __str__(self):
        return f'{self.name}: {self.level}'

    def __repr__(self):
        return f"Employee('{self.name}', '{self.level}')"

    @property
    def name(self):
        return self._name

    @name.setter
    def name(self, new_name):
        if not isinstance(new_name, str):
            raise TypeError("'name' must be a string.")
        self._name = new_name
        print(f"'name' updated to '{self.name}'.")

    @property
    def level(self):
        return self._level

    @level.setter
    def level(self, new_level):
        if not isinstance(new_level, str):
            raise TypeError("'level' must be a string.")
        if new_level not in Employee._base_salaries:
            raise ValueError(f"Invalid value '{new_level}' for 'level' attribute.")
# User Editable Region
        if hasattr(self, '_level') and new_level == self.level:
            raise ValueError(f"'{self.level}' is already the selected level.")            
# User Editable Region
        self._level = new_level
    
    @property
    def salary(self):
        return self._salary

charlie_brown = Employee('Charlie Brown', 'trainee')
print(charlie_brown)
print(f'Base salary: ${charlie_brown.salary}')
charlie_brown.level="trainee"

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 Salary Tracker - Step 31

GitHub Link: freeCodeCamp/curriculum/challenges/english/blocks/workshop-salary-tracker/68c9cab4b1118da59eecfc56.md at main · freeCodeCamp/freeCodeCamp · GitHub

Welcome to the forum @shsp10802,

I’m seeing this error in the console:

Traceback (most recent call last):
  File "main.py", line 54, in <module>
  File "main.py", line 43, in level
ValueError: 'trainee' is already the selected level

Try setting charlie_brown.level to “junior” to get past that.

Happy coding

or remove this line, it’s triggering the error and making the tests not pass

It really works! I should’ve known this simple mistake, thanks so much!!