Can you please take a look on below?
I am starting my journey with coding and do not know what is wrong in my code.
Probably I miss some digits or maybe logic?
Your code so far
function titleCase(str) {
var a=str.toLowerCase().split(" ");
var result ="";
for (i=0, i<a.length, i++);{
words = a[i].charAt[0].toUpperCase() + a[i].substr[1];
result = result + words;} {
return a;
}
titleCase("I'm a little tea pot");
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36
.
Link to the challenge:
There’s a couple of errors in your code.
- There shouldn’t be a semicolon after
i++)
(technically this isn’t a syntax error but placing a semicolon here causes a lot of bugs).
- The commas in the for-loop header should be semicolons:
for (i = 0; i < a.length; i++)
.
- There’s an extra
{
at the end of result = result + words; }
.
-
charAt
and substr
are functions, not arrays, so the brackets should be parentheses: charAt(0)
, substr(1)
- You seem to be returning the wrong variable.
Other than that your logic is pretty close. You just need a few tweaks to how you make the result
string.
Thanks a lot. I am still amateur in this big world;)
Now it looks like below, and what is most important - it works Thank you one more time !
var a=str.toLowerCase().split(" “);
var result =”";
for (i=0; i<a.length; i++){
words = a[i].charAt(0).toUpperCase() + a[i].substr(1);
result =result+ " “+ words;}
if (result.charAt(0) == ’ ') result = result.replace(” ", “”);
return result;
1 Like