Tell us what’s happening:
why wont this pass?
Your code so far
function titleCase(str) {
let newArr = [];
let arr = str.toLowerCase().split(' ');
for (let i = 0; i < arr.length; i++) {
newArr.push(' ');
newArr.push(arr[i][0].toUpperCase());
for (let j = 1; j < arr[i].length; j++) {
newArr.push(arr[i][j]);
}
}
return newArr.join('');
}
console.log(titleCase("sHoRt AnD sToUt"));
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 13020.55.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.77 Safari/537.36
.
Challenge: Title Case a Sentence
Link to the challenge:
Learn to code. Build projects. Earn certifications.Since 2015, 40,000 graduates have gotten jobs at tech companies including Google, Apple, Amazon, and Microsoft.
Here’s a comparison of your original array and your newArr.
This is why your .join isn’t working as you think it would.
I thought i figured it out? But now its not passing the test?
What does your code look like now?
i edited and updated the code in the forum
Perfect!
Now I’ve done a console.log on the newArr.join that you return, and wrapped it in <
and >
. Do you see something extra that doesn’t belong?
2 Likes
i Know its sloppy, but it works
function titleCase(str) {
let newArr = [];
let arr = str.toLowerCase().split(' ');
for (let i = 0; i < arr.length; i++) {
if (i > 0) {newArr.push(' ')}
newArr.push(arr[i][0].toUpperCase());
for (let j = 1; j < arr[i].length; j++) {
newArr.push(arr[i][j]);
}
}
return newArr.join('');
}
console.log(titleCase("sHoRt AnD sToUt"));
Thanks nhcarrigan! i truly appreciate the help!!
2 Likes
Glad you were able to get it to work!
1 Like