Build a Salary Tracker - Step 40

Tell us what’s happening:

I have replaced “self._salary” with :self.salary" in level setter. I still get an error. Following is my level setter function:

Your code so far

# User Editable Region
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]

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

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

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

	@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}'.")

	@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.')
		if hasattr(self, '_level') and new_level == self.level:
			raise ValueError(f'\'{self.level}\' is already the selected level.')
		if hasattr(self, '_level') and Employee._base_salaries[new_level] < Employee._base_salaries[self.level]:
			raise ValueError("Cannot change to lower level.")
		print(f'\'{self.name}\' promoted to \'{new_level}\'.')
		self.salary = Employee._base_salaries[new_level]
		self._level = new_level


	@salary.setter
	def salary(self, new_salary):
		if not isinstance(new_salary, (int, float)):
			raise TypeError("'salary' must be a number.")
		if hasattr(self, '_level') and new_salary < Employee._base_salaries[self.level]:
			raise ValueError(f'Salary must be higher than minimum salary ${Employee._base_salaries[self.level]}.')
		self._salary = new_salary
		print(f'Salary updated to ${new_salary}')

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

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

charlie_brown = Employee('Charlie Brown', 'trainee')
print(charlie_brown)
print(f'Base salary: ${charlie_brown.salary}')
charlie_brown.level = 'junior'
# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:153.0) Gecko/20100101 Firefox/153.0

Challenge Information:

Build a Salary Tracker - Step 40

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

Welcome to the forum @pbutala,

The new code you wrote is correct, but you may have inadvertently changed the starting code, which will cause the tests to fail.

Please reset this step and try again.

Happy coding

Welcome to the forum @pbutala

Salary updated to $1000 is missing a period at the end.

Please do not modify parts of the code you are not asked to modify.

Happy coding