LC 101-Ind - StringExercises06 - print 'Title Case' from 'title case'? - Wk2A Strings Ex Pt 3

StringExercises06 asks to use string methods we know to print ‘Title Case’ from ‘title case’.
Statement given is: let notTitle = ‘title case’;
The closest I can get is to print: ‘Title case title Case’ (NOT ‘Title Case’) w/ the following code:
console.log(${notTitle.replace('t',(notTitle.slice(0,1)).toUpperCase())} ${notTitle.replace('c',(notTitle.slice(6,7)).toUpperCase())});
I looked thru all our CH7 Stringing Characters Together reading materials and looking for answer on internet just got me more confused. I tried to declare and process two separate variables (title and case1) with initials caps but could still never figure out how to get rid of the verbiage I did not want. Any help would be appreciated. Thanks.

I used substring() method to seperate each word first.
Then used charAt() method for character search and then converted it to Uppercase using toUpperCase() method.
With method chaining I converted the case of the letters and
finally, Concatenated with template literals.

This took me a lot of time to figure out too. I tried Slice() method too at first.
Hope this Helps!!!

Thanks Suni - the ex. said to use string methods you(we) know to print 'Title Case' from the string 'title case'. So I was trying to use only the CH 7.5.1 Common String Methods listed (includes indexOf, toLowerCase, toUpperCase, trim, replace, slice) which do not include substring() and charAt() that you used. At the following text link: https://www.w3schools.com/jsref/jsref_obj_string.asp I could find String methods substring() and charAt() though. Can/Did anyone complete this ex. w/ CH 7.5.1 Common String Methods listed (includes indexOf, toLowerCase, toUpperCase, trim, replace, slice) only? If so, any hint would be appreciated.

@Ebbie You were super close!!!
You just forgot to slice.

Here’s the code:

console.log(${notTitle.replace('t',(notTitle.slice(0,1)).toUpperCase()).slice(0,5)} ${notTitle.slice(6, 10).replace('c',(notTitle.slice(6,7)).toUpperCase())});

Now this isn’t a permanent code that we could use for any other variable. I think we’d need a function for that but it works!

Thank you very much @StephNau; appreciated.

1 Like