//sample solution
function capitalizeFirst(str) {
return str.charAt(0).toUpperCase() + str.substring(1, str.length);
}
function capitalizeName(name){
//The string below contains a lower case version of name. Let's use this from now on.
var lowerName = name.toLowerCase();
var spaceIndex = lowerName.indexOf(' ');
var first = lowerName.substring(0, spaceIndex);
//Complete the function body below.
var last = lowerName.substring(spaceIndex+1,lowerName.length);
return capitalizeFirst(first)+" "+capitalizeFirst(last);
}
//test
capitalizeName("jOhN doE");
No comments:
Post a Comment