https://www.codewars.com/kata/57e3f79c9cb119374600046b
Codewars - Achieve mastery through coding practice and developer mentorship
A coding practice website for all programming levels – Join a community of over 3 million developers and improve your coding skills in over 55 programming languages!
www.codewars.com
DESCRIPTION:
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!"
코드
function hello(name) {
if(!name) return "Hello, World!";
name = name[0].toUpperCase() + name.slice(1).toLowerCase();
return `Hello, ${name}!`;
}
댓글