Now, the last thing that I want to show you that you can do with strings is, you can use a method called 1
toUpperCase() 2
that changes all of the characters in your string to uppercase. 3
So as we have done before, we simply take the variable, and then we write a dot, and then we use toUpperCase 4
to turn every single character in the string to the uppercase version of it. 5
So let me show you what this looks like in real life. 6
So I have a variable that is called name and it contains the string Angela. 7
Now, if I write name.toUppercase, and then I add some empty parentheses, and finish off my statement 8
with a semi-colon, 9
and now if I hit command enter, you can see that in the console I get the string that's contained a name 10
printed out with every single character changed to the upper case. 11
Now at the moment this functionality is completed and then this data is lost. 12
So inside here, for example if I just wrote name, which is my variable, you can see that it's still lowercase. 13
So if you wanted this to be saved to this variable then all we need to do is say that name equals the 14
old version of name, which is this, changed to uppercase, and then reassigned to the same variable. 15
So now if I hit run and I type name into the console to try and pull up the value that’s contained inside 16
this variable, you can see it is now all capitalized. 17
Now we can change it in the other direction as well. 18
So, for example, if I wrote name now equals the previous version of name, which at this point is all 19
uppercase, .toLowerCase, then 20
now, the final version of name is actually all fully lowercase, 21
even the first a. It’s all been turned into lowercase. 22
Now that's pretty easy and it's pretty useful as well because sometimes you might want to ask the user 23
for, say, a prompt and you ask them for ‘What is your name?’. 24
And they end up giving you their name in, say, all lowercase, right? 25
And that doesn't really look very good when you print it out, say in an alert. 26
It doesn't look that great and it won't be consistent across different users. 27
Now if you've been watching along with the previous lessons and you've absorbed the knowledge then you 28
should now be able to use everything that you've learnt including how to slice strings up, how to concatenate 29
strings, and also how to change the casing in order to complete the next challenge. 30
So what I want you to do is to create a prompt that asks the user for their name, 31
but if they give you a name that is uppercase or lowercase, I want you to be able to send them an alert 32
that says Hello, 33
and then their name, so for example Angela, but the name has to be capitalized, but only for the first 34
character and none of the rest of the characters. 35
So I want you to think about this problem, 36
and break it down into smaller chunks that you can tackle one at a time. 37
Now, while there are much easier ways of doing it if you search Stack Overflow or Google, I want you 38
to only use the things that we've talked about in this module. 39
So everything that you need to complete this challenge is within the lessons of this module. 40
So pause the video now and see if you can complete this challenge.