Title Case a Sentence nothion is defined

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.

Link to the challenge:

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.

@rjk welcome to the forum.

@camperextraordinaire
yea its unfinished i need to see what its doing so i can finish and i don’t know how to see it

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. :slight_smile:

yea that is what I’m getting to I can scrap it. I think I’m just not going to get JavaScript. it’s sad. I did well on the other stuff.

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.

  1. Split the string into words
  2. Make sure the string is all lower case
  3. Capitalise each words first character
  4. 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.

https://www.w3schools.com/jsref/jsref_obj_string.asp

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.

Everyone starts somewhere, 99% of professional developers use google daily but they’re just good at googling it and searching MDN etc.

If you really aren’t enjoying it take a break do something you are enjoying and then come back if you want to start again.

i’m looking at new ways now may one will work for me

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.

I think I got it


[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]

Well, that just should be at the end of the function body, not inside the for loop. Done!

yea I like the short ones too but I had to walk this one out

I don’t remember a map whats that do

It didn’t work the last return not working

no my code isn’t working still

Myarr is not defined

ok reset code and try again tomorrow