Tell us what’s happening:
I reached myself this solution so far by reading the hints.
Could you please check and help me with hints? I defined 2 steps but happy to work on more needed ones.
Thanks in advance!
Your code so far
function titleCase(str) {
//1.Return the str with the first letter of each word capitalised
for(let i = 0; i >= str.length; i++) {
return str[i].split("").toLowerCase(str).toUpperCase(str)
}
return str;
}
titleCase("I'm a little tea pot");
function titleCase(str) {
//1.Return the str with the first letter of each word capitalised
for(let i = 0; i >= str.length; i++) {
return str[i].split("").toLowerCase(str).toUpperCase(str)
}
return str;
}
titleCase("I'm a little tea pot");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36.
This line means your for loop will never run. Your for loop will only run when i is greater than or equal to str.length, and since i is initialised with a value of 0, the loop doesn’t run.
What are you trying to accomplish with this line? str[i] gets the character from str at position i. split("") tries to turn that character into an array? .toLowerCase(str) is incorrect syntax. .toLowerCase() does not take arguments. .toUpperCase(str) is also incorrect syntax. Assuming these two were written correctly, you’d be turning the string to lower case and back to upper case?
Regarding your last question, yes, it is advised first to make the word lower case and then convert to Upper case.
Will adjust the foor loop.
I am trying to solve this challenge but I cant work out the syntax
The challenge asks for the first letter to be upper case and the rest to be lower case.
Why would you convert the entire word to lower case and then convert the entire word to upper case?