-
-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathanotherHello.js
More file actions
18 lines (13 loc) · 626 Bytes
/
anotherHello.js
File metadata and controls
18 lines (13 loc) · 626 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
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:
hello "john" => "Hello, John!"
hello "aliCE" => "Hello, Alice!"
hello => "Hello, World!" # name not given
hello '' => "Hello, World!" # name is an empty String
*/
//Answer//
function hello(name="World!") {
return name===''||name==="World!"?'Hello, World!':`Hello, ${name[0].toUpperCase()+name.slice(-name.length+1).toLowerCase()}!`;
}