---
id: 69c0dc6914ac0434f0cc52b7
title: Step 28
challengeType: 20
dashedName: step-28
---

# --description--

To ensure that `new_level` is the right type, create an `if` statement that raises a `TypeError` with the message `'level' must be a string.` when `new_level` is not an instance of `str`.

# --hints--

You should have an `if` statement inside your `level` setter.

```js
({ test: () => assert(runPython(`_Node(_code).find_class("Employee").find_functions("level")[1].find_ifs()[0]`)) })
```

You should raise a `TypeError` with the message `'level' must be a string.` when `new_level` is not an instance of `str`.

```js
({ test: () => runPython(`
  emp = Employee('Frank', 'trainee')
  non_levels = [0, True, []]
  for i in non_levels:
    try:
      emp.level = i
    except TypeError as e:
      assert str(e) == "'level' must be a string."
    else:
      assert False, "Expected to raise TypeError with non-string new_level"
`) })
```

You should not raise any exception when `new_level` is a string.

```js
({ test: () => runPython(`
  emp = Employee('Frank', 'trainee')
  try:
    emp.level = "junior"
  except TypeError:
    assert False, "Expected not to raise TypeError with string new_level"
`) })
```

# --seed--

## --seed-contents--

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

    def __init__(self, name, level):
        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):
--fcc-editable-region--
        
--fcc-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}')

```
