课程: JavaScript Practice: String Manipulation
Solution: Transform user input to lowercase - JavaScript教程
课程: JavaScript Practice: String Manipulation
Solution: Transform user input to lowercase
- [Instructor] In this challenge, we're given some user input that contains upper and lowercase letters. It represents a city, so we can more or less assume that a letter capitalized at the end of the word, or maybe a lowercase letter at the very beginning might be a typo on the part of the user. The solution for this challenge is actually pretty straightforward. We have the city string that is passed to our transform city to lowercase function on line 10. For this challenge, we just need to return the updated string in all lowercase and can reach for the string method, toLowerCase. So let's go ahead and start with return on line 12. And we're going to take our city and apply the toLowerCase method. One thing I want to point out about this method, actually a few things. One is that you can see toLowerCase is in what's called camel case, so the t is lowercase and then the L and the C are uppercase. That's one thing to keep in mind. I know a few times when I've used this myself, I've accidentally made the word lowercase, capital L, and then everything else lowercase. So just keep that in mind with this method. The next thing is that the toLowerCase method does not take any arguments. So all you have to do is just apply it to whatever string that you want to make lowercase and voila, that's it. So let's go ahead and run it. And excellent work. You can see that it returned the city Fuquay Varina, which is my hometown, in all lowercase letters. Excellent work.
内容
-
-
-
Solution: Determine password length2 分钟 36 秒
-
Solution: Trim a user's new password2 分钟 8 秒
-
Solution: Check phone number format1 分钟 54 秒
-
Solution: Transform user input to lowercase1 分钟 39 秒
-
Solution: Display a page heading in uppercase1 分钟 3 秒
-
Solution: Does the message include "fun"?2 分钟 15 秒
-
Solution: Split your email list2 分钟 8 秒
-
Solution: Slice your account number display1 分钟 59 秒
-
Solution: Replace the typo1 分钟 44 秒
-
Solution: Concat first and last name2 分钟 21 秒
-
-