Project 18: Registration Flow
JS Wizard
Builds on these lessons
Step 1 of 3
Project
The Module Pattern
Wrap validation logic in an immediately-invoked function expression that returns just the public pieces you want exposed, keeping an internal errorCount variable private. The module pattern is how JS achieved "private" state and a clean public API before native modules existed.
🎯 Your Task
Please add the exact code shown in the light gray box below to your editor.Do not delete your previous code, just insert these new lines in the correct place!
const FormValidator = (function () {
let errorCount = 0;
function validateEmail(email) {
const isValid = email.includes("@");
if (!isValid) errorCount += 1;
return isValid;
}
return { validateEmail };
})();
console.log(FormValidator.validateEmail("not-an-email"));
console.log(FormValidator.validateEmail("jordan@example.com"));