for Pete sake what is happening here? I keep changing and nothing is working:face_with_symbols_over_mouth:
Your code so far
function titleCase(str) {
var myStr=(arr.splice(' '));
var arr=0
for (var i=0; myStr.length;i++){
myStr.toLowerCase();
myStr.replace (0,myStr.toUpperCase())
}
return myStr;
}
titleCase("I'm a little tea pot");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:67.0) Gecko/20100101 Firefox/67.0.
String methods return a new string rather than modifying the original, so you have to do something like
myStr = myStr.toLowerCase();
Check the appropriate parameters to replace()
The middle expression in a for statement needs to be a Boolean expression, not just a number, so the for loop will stop when the expression becomes false.
I’d like to add once you sort the variable declaration and follow Dawsons advice with console logging.
If you’re unsure why something isnt working at all double check the methods you are calling on MDN or w3schools etc. It will definetly help solve some of these quicker.
You can it’s just not as straight forward as HTML and CSS. For instance, when you have loops write each step out, use a console.log inside the loop to print what is happening to understand what is going wrong.
Thing about what the code needs to do step by step.
Split the string into words
Make sure the string is all lower case
Capitalise each words first character
Return the new words as a string
Look up methods on MDN for strings and Arrays, how to get each word individually, how to get the first character of each word, how to change that character.
When you’re looking at these method read what the parameters need to take and then check again what you’re giving it by console logging before you call the method.
I’m just not feeling it now I was enjoying it. like my console.log don’t work I watch other people on youtube and all their stuff works so I try and it doesn’t I don’t understand and I feel like washout before I start. I just don’t know what to do.
These methods don’t change the value, instead they return a new value. You can chain those methods if you like. Also, you can’t do that on an array, it should be myStr[i].whatever.
i < myStr.length; the i < is missing.
What does splice do? To split the string, use arr.split(' ');.
There are more issues, but I’ll get to them later.
[details="Summary"]
function titleCase(str) {
var myArr = str.toLowerCase().split(' ');
//assigns new array to sting in lower and split
for (var i = 0; i < myArr.length; i++)
//assigns i to first character then counts
{
var j = []
//placeholder
{
myArr[i] = myArr[i].replace(myArr[i].charAt(0), function replace(j) {
return j.toUpperCase();
/* alot happen here the arr that is counted is replaced and then place in j
then returned in upper case so now all the first letters or in caps and in j*/
});
console.log(myArr);
}
return myArr.join(' ');
}//return the array back to together with caps
}
titleCase("I'm a little tea pot");
[/details]