-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprogram_32.js
28 lines (26 loc) · 1.21 KB
/
program_32.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"use strict";
/*
* Checking Usernames: Do the following to create a program that simulates how websites
* ensure that everyone has a unique username.
• Make a list of five or more usernames called current_users.
• Make another list of five usernames called new_users.
* Make sure one or two of the new usernames are also in the current_users list.
• Loop through the new_users list to see if each new username has already been used.
* If it has, print a message that the person will need to enter a new username.
* If a username has not been used, print a message saying that the username is available.
*/
const currentUsers = ['huzaifa', 'shuja', 'moiz', 'faraz', 'bilal'];
const newUsers = ['abdullah', 'bilal', 'rohan', 'shuja'];
// Function to check if a username is already taken
function isUserNameTaken(userName) {
return currentUsers.some(user => user.toLowerCase() === userName.toLowerCase());
}
// Loop through newUsers to check if each username is available
for (const newUser of newUsers) {
if (isUserNameTaken(newUser)) {
console.log(`The username '${newUser}' has already been taken. Please enter a new username.`);
}
else {
console.log(`The username '${newUser}' is available.`);
}
}