-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq12.ts
More file actions
22 lines (16 loc) · 765 Bytes
/
q12.ts
File metadata and controls
22 lines (16 loc) · 765 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// Greetings: Start with the array you used in Exercise 11, but instead of just printing each person’s name, print a message to them. The text of each message should be the same, but each message should be personalized with the person’s name.
export default function q12() {
console.log("\n");
// Define an array of names
let names: string[] = ["John", "Jane", "Jim", "Jackie"];
// Print each name with a greeting using a for loop
for (let i = 0; i < names.length; i++) {
console.log("Hello " + names[i] + ", How are you today?");
}
console.log("\n");
// Print each name with a greeting using forEach method
names.forEach(function(name) {
console.log("Hello " + name + ", How are you today?");
});
}
q12();