I feel maybe it’s the return line that isn’t working, maybe I can’t add toUpperCase to charAt?
Your code so far
function titleCase(str) {
var lowerCase = str.toLowerCase(); // make it all lowercase
var newStr = lowerCase.split(" "); // separate the strings
for (i = 0; i < newStr; i++) { // loop through all separated strings
return newStr[i].charAt(0).toUpperCase + newStr.slice(1); // return the first letter capitalized with the addition of the the rest of the string
}
}
console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36.
Hmm I keep forgetting return only runs once. Is the rest of the code ok?
Not sure what to replace return with. This ins’t working
function titleCase(str) {
var lowerCase = str.toLowerCase(); // make it all lowercase
var newStr = lowerCase.split(" "); // separate the strings
for (i = 0; i < newStr; i++) { // loop through all separated strings
newStr[i].charAt(0).toUpperCase + newStr.slice(1); // return the first letter capitalized with the addition of the the rest of the string
}
return newStr;
}
console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));
I don’t know how to store this. Seems to be what I’m missing, but I can’t figure it out. Also the solutions are solving this in a different way, so I can’t really use it as a reference like usual (they’re not using a for loop)
function titleCase(str) {
var lowerCase = str.toLowerCase(); // make it all lowercase
var newStr = lowerCase.split(" "); // separate the strings
for (let i = 0; i < newStr; i++) { // loop through all separated strings
newStr[i].charAt(0).toUpperCase + newStr[i].slice(1); // return the first letter capitalized with the addition of the the rest of the string
}
return newStr.join(" ");
}
console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));
Sorry I can’t figure this out. I tried to add a new variable for finalStr but it’s not working. Can you give me the solution to this now? I’m sure I’ll understand if you do.
function titleCase(str) {
var lowerCase = str.toLowerCase(); // make it all lowercase
var newStr = lowerCase.split(" "); // separate the strings
var finalStr = "";
for (let i = 0; i < newStr.length; i++) { // loop through all separated strings
var finalStr = newStr[i].charAt(0).toUpperCase() + newStr[i].slice(1); // return the first letter capitalized with the addition of the the rest of the string
}
return finalStr.join(" ");
}
console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));
I can’t figure it out. Giving me a answer now would help me learn. I’m sorry I can’t seem to figure it out
function titleCase(str) {
var lowerCase = str.toLowerCase(); // make it all lowercase
var newStr = lowerCase.split(" "); // separate the strings
var finalStr = [];
for (let i = 0; i < newStr.length; i++) { // loop through all separated strings
var finalStr = newStr[i].charAt(0).toUpperCase() + newStr[i].slice(1); // return the first letter capitalized with the addition of the the rest of the string
}
return finalStr.join(" ");
}
console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));
Yeah thanks, I have gotten better slowly but surely. I just want to make sure I learned the reason I had the last problem. The problem was I couldn’t use join because finalStr was a string not an array?
So that I can learn better to read the docs, where would I be able to find that bit of information next time?