JavaScript Username Generator 2: trim, toLowerCase, substring, replace, and if

preview_player
Показать описание
In this video we extend our previous example of an HTML page with JavaScript that generated a username from some data entered by a user. We looked up various code snippets on the W3schools site and incorporated them into our code. We used the trim() method to eliminate any leading of trailing space on the user's text entries. We used to the toLowerCase() method to put the user's text entry into all lower-case letters. We used the substring() method to extract just the first initial from the user's first-name entry. We used the replace() method to substitue any spaces or hyphens in the last-name entry with underscores. We used a simple string-comparison if to test that the user entered something for the first name.
Рекомендации по теме