Hey everybody,
I think i am still confused about the loop stuff. And I really dont know how to proceed. Below, Im not looking for the solution, I just need to understand how should I do and hopefully someone could explain me very clearly Thanks !
For example in the challenge called “Title Case a Sentence” I made this :
First of all, my strategy is :
-
From String Sentence => Array of words of that sentence : [“i’m”, “a”, “little”, “tea”, “pot”]
NO PROBLEM FOR THIS its “Line 2” in the code below. -
From [“i’m”, “a”, “little”, “tea”, “pot”] => [ [“i”," ’ ",“m”], [“a”], [“l”,“i”,“t”,“t”,“l”,“e”], [“t”,“e”,“a”], [“p”,“o”,“t”] ]
HERE THE PROBLEM START, to MAKE THIS I WANT TO MAKE A LOOP, AND ITS RETURNING ME ONLY THE FIRST ARRAY -
From [ [“i”," ’ ",“m”], [“a”], [“l”,“i”,“t”,“t”,“l”,“e”], [“t”,“e”,“a”], [“p”,“o”,“t”] ] => replace first index of the array to Uppercase.
FIRST I NEED TO FIGURE OUT THE LOOP
function titleCase(str) { //input: (“I’m a little tea pot”);
arrayWord = str.toLowerCase().split(" "); //output: [“i’m”, “a”, “little”, “tea”, “pot”]
for (var i = 0; i < arrayWord.length; i++){
return arrayWord[i].split(""); //output : problem only returning the first [0]
}
}
titleCase(“I’m a little tea pot”);