1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
/** Greets one person, several times over. */
export class Greeter {
#name;
constructor(name) {
this.#name = name;
}
/** Prints the greeting `times` times and says whether the name is capitalised. */
greet(times = 1) {
const pattern = /^[A-Z]/;
for (let i = 1; i <= times; i++) {
console.log(`Hello, ${this.#name}! (${i})`);
}
return pattern.test(this.#name);
}
}
|