-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq19.js
More file actions
68 lines (53 loc) · 3.25 KB
/
q19.js
File metadata and controls
68 lines (53 loc) · 3.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"use strict";
// Answer At Line 70;
Object.defineProperty(exports, "__esModule", { value: true });
// Changing Guest List: You just heard that one of your guests can’t make the dinner, so you need to send out a new set of invitations. You’ll have to think of someone else to invite.
/*
Start with your program from Exercise 14. Add a print statement at the end of your program stating the name of the guest who can’t make it.
• Modify your list, replacing the name of the guest who can’t make it with the name of the new person you are inviting.
• Print a second set of invitation messages, one for each person who is still in your list.
*/
function q19() {
const guestList = ['Sir Daniyal Nagori', 'Imran Khan', 'Bitcoin', 'Dollars'];
const unableToAttend = "Dawood Bhai";
const newInvite = 'Miss Hira Khan';
console.log(`${unableToAttend} can't make it to the party. \n`);
for (let guest of guestList) {
if (guest === unableToAttend) {
guest = newInvite;
}
console.log(`Dear ${guest}, please come to the party!`);
}
/*
More Guests: You just found a bigger dinner table, so now more space is available. Think of three more guests to invite to dinner.
• Start with your program from Exercise 15. Add a print statement to the end of your program informing people that you found a bigger dinner table.
• Add one new guest to the beginning of your array.
• Add one new guest to the middle of your array. • Use append() to add one new guest to the end of your list. • Print a new set of invitation messages, one for each person in your list.
*/
console.log(`\nGood news! We found a bigger dinner table.\n`);
guestList.unshift('Sir Zia Khan');
guestList.splice(3, 0, 'Bill Gates');
guestList.push('Mark zuckerberg');
/*
Shrinking Guest List: You just found out that your new dinner table won’t arrive in time for the dinner, and you have space for only two guests.
• Start with your program from Exercise 16. Add a new line that prints a message saying that you can invite only two people for dinner.
• Remove guests from your list one at a time until only two names remain in your list. Each time you pop a name from your list, print a message to that person letting them know you’re sorry you can’t invite them to dinner.
• Print a message to each of the two people still on your list, letting them know they’re still invited.
• Remove the last two names from your list, so you have an empty list. Print your list to make sure you actually have an empty list at the end of your program.
*/
console.log(`Sorry, we can only invite two people for dinner.\n`);
while (guestList.length > 2) {
const removedGuest = guestList.pop();
console.log(`Sorry, ${removedGuest}, we can't invite you to dinner.`);
}
console.log("\n");
for (let guest of guestList) {
console.log(`Dear ${guest}, please come to the party!`);
}
console.log("\n");
guestList.length = 2;
console.log(guestList);
console.log(`You are inviting ${guestList.length} people to dinner.`);
}
exports.default = q19;
q19();