Can anyone tell me why this is not working?
Your code so far
function titleCase(str) {
str=str.toLowerCase();
var output=" ";
var newWord=true;
for(var i=0; i<str.length; i++){
if (newWord){
newWord = false;
output+=str[i].toUpperCase()
}else output+=str[i];
if (str[i]===" "){
newWord = true;
}
}
console.log(output+" .");
return output+" .";
}
titleCase("I'm a little tea pot");
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36
.
Link to the challenge: