Recap Challenge
Part of the Object Oriented Programming section of Coddy's JavaScript journey — lesson 46 of 56.
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:
- Add a getter for
emailthat returns the current email value - Add a setter for
emailthat:- 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
- Logs exactly:
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
1Objects & The this Keyword
Quick Review: ObjectsAdding Methods to ObjectsUnderstanding the this KeywordConstructor FunctionsThe new KeywordRecap Challenge7 Inheritance & The extends Key
InheritanceThe "is-a" RelationshipThe extends KeywordThe super() MethodInheriting Properties&MethodsRecap Challenge2Organizing Code
What are Modules?Exporting with exportImporting with importDefault vs. Named Exports8Organizing OOP Code
Organize Classes into Modules11Project: A Shape Renderer
Setup: Shape Class & ExportCircle Class Inheritance9Static Methods & Properties
Class-Level vs. Instance-LevelStatic PropertiesStatic Utility MethodsRecap challenge12Getters & Setters
The get and set KeywordsComputed PropertiesValidation and Side EffectsRecap Challenge