课程: JavaScript Practice: String Manipulation
Solution: Replace the typo
- [Instructor] In this challenge, we are given a string of emails again, but this time we need to just update a typo and return the updated string. In order to solve this challenge we can use the string method replace. Replace has two parameters, the pattern that needs to be replaced and then the actual replacement. For this challenge, we needed to replace any emails that had the domain pgn.com and replace them with atn.com. For all of my succession fans out there. In our test code, we'll be returning the result of the fixed typo function on line nine with the email list passed in as an argument. Let's start in the fixed typo function there on line 10. The first thing we'll do is write our return statement on line 12. So let's go ahead and write return, and then we know that we're going to be updating this email list so we'll go ahead and type that and then replace. All right, step one. Next, we need to pass in our arguments. The pattern that needs to be replaced is pgn.com so that will be the string pgn.com. That is our first argument. That is what is going to be replaced in our string. Then we need to add what that string is going to be replaced with. So here it's another string atn.com. So we're returning our email list and we're replacing any string that has pgn.com with atn.com. Let's go ahead and run that. And excellent. So now we have our new string, our updated string and everyone has the exact same domain name. Great 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 秒
-
-