Am So So proud and happy to find a solution by myself for the challenge but FCC keep says error am getting a correct output when i debug at visual studio code.
here my solution
function returnCapitilize(givenString){
let myarry=givenString.split(" “);
let result=”";
for(let i=0;i<myarry.length;i++){
result=result+" "+ myarry[i][0].toUpperCase()+(myarry[i].slice(1,myarry[i].length)).toLowerCase();
}
return result;
}
What error are you getting?
at Free code Camp when i run the test it only give right icon for returning string all the reset give me red x icon …does that min we only give the code only way the right it??Test my code
I found your bug. Make sure you remove all the white spaces before and after the result. A useful function is: trim()
which works for strings.
Basically you have an extra space at the beginning of the result string. That’s coming from the code which is inside the for loop
-> result+" "+...
the reason why i add white space is to be read like If
givenString=“my name is kumenger” with out the space the out put is MyNameIsKumenger but with the space it will be My Name Is Kumenger…
I understand, and that’s ok. But it adds an extra space in front and it becomes: " My Name Is Kumenger"
.
Use the .trim()
function on the result
when you return it, and it’ll work fine!
Thank you bro just works like a Charm well done passed it.Wowo.it feels so good find things on my way .Thank you now all Right icons
function titleCase(givenString){
let myarry=givenString.split(" “);
let result=”";
for(let i=0;i<myarry.length;i++){
result=result+" "+ myarry[i][0].toUpperCase()+(myarry[i].slice(1,myarry[i].length)).toLowerCase();
}
return result.trim();
}
Yes, the feeling is amazing when you accomplish something! Well done @kumenger!
Keep up the good work!