Tell us what’s happening:
I always look at the challenge guide page after I’ve completed an exercise to compare my (awful) solutions against the ones provided. I try to avoid it otherwise. That has changed since I started the basic algorithm scripting section of the JavaScript course. Now I’ll usually find myself looking at some pseudocode or steps I’ve written, unable to translate it into JavaScript without googling methods or syntax, et cetera.
I guess my question is, is this to be expected during this section? Or is the assumption that I should have retained enough information from the previous exercises to be able to solve these algorithms without a search engine? For context, I’ve added my working solution and one solution from the challenge guide page:
**Your code so far**
function titleCase(str) {
let lowerArray = str.split(' ');
let upperStr = ``;
for (let i in lowerArray) {
lowerArray[i] =
lowerArray[i][0].toUpperCase() + lowerArray[i].slice(1).toLowerCase();
}
for (let j = 0; j < lowerArray.length; j++) {
upperStr += `${lowerArray[j]} `;
}
return upperStr.trimEnd();
}
titleCase("I'm a little tea pot");
**Challenge Guide Solution**
function titleCase(str) {
return str
.toLowerCase()
.replace(/(^|\s)\S/g, L => L.toUpperCase());
}
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.5005.61 Safari/537.36
Challenge: Title Case a Sentence
Link to the challenge: