Menu
Coddy logo textTech

Recap Challenge

Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 46 of 56.

challenge icon

Challenge

You're given a UserProfile class with the username property already implemented. Your task is to complete the implementation for the email property using getters and setters:

  1. Add a getter for email that returns the current email value
  2. Add a setter for email that:
    • Validates the email contains the '@' character
    • If valid:
      • Updates the email to the new value
      • Logs exactly: Email updated to [newEmail]
    • If invalid:
      • Logs exactly: Invalid email!
      • Does NOT update the email

Try it yourself

import { UserProfile } from './user.js';

// Test code - don't modify
const user = new UserProfile("alice123", "alice@email.com");

user.email = "bob@email.com";      // Valid - should log success
user.email = "invalid-email";      // Invalid - should log error

All lessons in Object Oriented Programming