-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatroomStatus.js
More file actions
37 lines (35 loc) · 1.25 KB
/
chatroomStatus.js
File metadata and controls
37 lines (35 loc) · 1.25 KB
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
29
30
31
32
33
34
35
36
37
// Write a function that returns the number of users in a chatroom based on the following rules:
// If there is no one, return "no one online".
// If there is 1 person, return "user1 online".
// If there are 2 people, return "user1 and user2 online".
// If there are n>2 people, return the first two names and add "and n-2 more online".
// For example, if there are 5 users, return:
// "user1, user2 and 3 more online"
// Examples:
// chatroomStatus([]) ➞ "no one online"
// chatroomStatus(["paRIE_to"]) ➞ "paRIE_to online"
// chatroomStatus(["s234f", "mailbox2"]) ➞ "s234f and mailbox2 online"
// chatroomStatus(["pap_ier44", "townieBOY", "panda321", "motor_bike5", "sandwichmaker833", "violinist91"])
// ➞ "pap_ier44, townieBOY and 4 more online"
function chatroomStatus(users) {
// console.log(users.length);
if (users.length === 0) {
return "no one online";
} else if (users.length === 1) {
return `${users[0]} online`;
} else if (users.length === 2) {
return `${users[0]} and ${users[1]} online`;
} else {
return `${users[0]}, ${users[1]} and ${users.length - 2} more online`;
}
}
console.log(
chatroomStatus([
"pap_ier44",
"townieBOY",
"panda321",
"motor_bike5",
"sandwichmaker833",
"violinist91",
])
);