Project 16: Login Screen
JS Wizard
Builds on these lessons
Step 1 of 3
Project
A Closure for a Login Attempt Counter
Write createAttemptTracker(), a function that declares a local attempts variable and returns an inner function that increments and returns it. Every call to the returned function still remembers attempts, even though createAttemptTracker already finished running — that's a closure.
🎯 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!
function createAttemptTracker() {
let attempts = 0;
return function () {
attempts += 1;
return attempts;
};
}
const trackLoginAttempt = createAttemptTracker();
console.log(trackLoginAttempt());
console.log(trackLoginAttempt());