I would be forever grateful if you could enlighten me how to get it to work. Currently when I run it it gives the alert upon the first entered username.
let userName1;
let userName2;
let userName3;
alcoholAgeCheck();
alcoholAgeCheck(userName2);
alcoholAgeCheck(userName3);
function alcoholAgeCheck() {
userName1 = prompt('Enter name');
if (userName1 === userName2 || userName1 === userName3) {
alert('Sorry, you may only use the same name once');
} else if (userName2 === userName1 || userName2 === userName3) {
alert('Sorry, you may only use the same name once');
}
}
Save all the previous inputs in a variable, and check whether the new input is in the set.
const userNames = new Set();
function alcoholAgeCheck() {
userName = prompt('Enter name');
if (userNames.has(userName)) {
alert('Sorry, you may only use the same name once');
} else {
userNames.add(userName);
}
}
alcoholAgeCheck();
alcoholAgeCheck();
alcoholAgeCheck();
console.log(Array.from(userNames));