-
Notifications
You must be signed in to change notification settings - Fork 0
/
Hello, Name or World!
27 lines (16 loc) · 770 Bytes
/
Hello, Name or World!
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
/*
Define a method hello that returns "Hello, Name!" to a given name, or says Hello, World! if name is not given (or passed as an empty String).
Assuming that name is a String and it checks for user typos to return a name with a first capital letter (Xxxx).
Examples:
* With `name` = "john" => return "Hello, John!"
* With `name` = "aliCE" => return "Hello, Alice!"
* With `name` not given
or `name` = "" => return "Hello, World!"
*/
export function hello(name = ''): string {
return `Hello, ${!name ? 'World!' : name[0].toUpperCase() + name.slice(1).toLowerCase() + '!'}`;
}
//Alternative way
export function hello(name = ''): string {
return name === '' ? 'Hello, World!' : `Hello, ${name[0].toUpperCase() + name.slice(1).toLowerCase()}!`;
}