Tell us what’s happening:
I have written a code that gets what is asked for, which is capitalise only the first letter of each word.
I have done that in a totally different working way but the website doesnt accept it.
Your code so far
function titleCase(str) {
let string = str.toLowerCase();
let arr = string.split(' ');
let upperCase;
let sentence = '';
let newArr = [];
for(let i=0; i<arr.length; i++){
upperCase = arr[i][0].toUpperCase();
newArr.push(upperCase + arr[i].slice(1));
sentence += newArr[i] + ' ';
}
return sentence;
}
titleCase("sHoRt AnD sToUt");
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36
.
Challenge: Title Case a Sentence
Link to the challenge: