Build a Salary Tracker - Step 34

Tell us what’s happening:

I am a bit baffled by the unit test

  1. the code definitely has 2nd if statement yet the test keep saying “I should have second if statement in your salary setter”
  2. I tried both comparing new_salary with self._salary or Employee._base_salaries yet both erro
  3. I checked if there’s missing text or something yet nothing

what is the issue here ?
I have attached both if condition, if anyone can help me

Your code so far

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

    def __init__(self, name, level):
        if not (isinstance(name, str) and isinstance(level, str)):
            raise TypeError("'name' and 'level' attribute must be of type 'str'.")
        if level not in Employee._base_salaries:
            raise ValueError(f"Invalid value '{level}' for 'level' attribute.")
        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 new_level not in Employee._base_salaries:
            raise ValueError(f"Invalid value '{new_level}' for 'level' attribute.")
        if new_level == self.level:
            raise ValueError(f"'{self.level}' is already the selected level.")
        if Employee._base_salaries[new_level] < Employee._base_salaries[self.level]:
            raise ValueError(f"Cannot change to lower level.")
        print(f"'{self.name}' promoted to '{new_level}'.")
        self._salary = Employee._base_salaries[new_level]
        self._level = new_level

    @property
    def salary(self):
        return self._salary

# User Editable Region

    @salary.setter
    def salary(self, new_salary):
        if not isinstance(new_salary, (int, float)):
            raise TypeError("'salary' must be a number.")
        
        # This one failed
        # if new_salary < Employee._base_salaries[self._level]:
        #     raise ValueError(f"Salary must be higher than minimum salary ${Employee._base_salaries[self._level]}")

        # This one failed too
        if new_salary < self._salary:
            raise ValueError(f"Salary must be higher than minimum salary ${self._salary}")
            
        self._salary = new_salary
        print(f'Salary updated to ${self.salary}.')

# User Editable Region


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

charlie_brown.level = 'junior'
charlie_brown.salary = 1500

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36

Challenge Information:

Build a Salary Tracker - Step 34

in this one you are free to write any condition

the tests are checking that there is an if as requested

and then the tests are trying to use the salary method to check if the correct error is raised, and that it is not raised when not needed

so focus on your error message, please check carefully the end of the instructions:

followed by the base salary for the current level and a period.

you are missing the last thing mentioned

I would also remove this, triggering the error in the editor and not from the tests will make the tests fail

Thank you for you reply . I finally did it by :

  • removing the last line charlie_brown.salary = 1500
  • use self.level on the conditional checking if new_salary < Employee._base_salaries[self.level]: instead of self._level . honestly idk why the test reject self._level even though it is functionally the same since there’s no validation or anything on level getter