JS implementation of random output uppercase and lowercase letters code

Source: Internet
Author: User

JS implementation of the random output case letter code:
This section describes how to use JavaScript to output random uppercase or lowercase letters, hoping to give you more or less help.
The code is as follows:

functiongetcharacter (flag) {varCharacter= ""; if(flag=== "Lower") {character= String.fromCharCode (Math.floor (Math.random () *26) + "a". charCodeAt (0)); }   if(flag=== "Upper") {character= String.fromCharCode (Math.floor (Math.random () *26) + "A". charCodeAt (0)); }   returncharacter;} functionGetuppercharacter () {returnGetcharacter ("Upper");; }functionGetlowercharacter () {returnGetcharacter ("Lower");; } console.log (Getuppercharacter ()); Console.log (Getlowercharacter ());

The above code to achieve our requirements, to be able to randomly output capital letters or small letters, the principle is very simple, is the use of uppercase letters or lowercase Unicode code of the interval to achieve, more content here is not more introduced, you can see the relevant reading.
Related reading:
The 1.fromCharCode () function can refer to the JS fromCharCode () function usage for a brief introduction to the chapter.
The 2.math.floor () function can be found in the Math.floor () method section of JavaScript .
The 3.math.random () function can refer to the JS random function math.random () section.
The 4.charCodeAt () function can refer to the charCodeAt () method section of the JavaScript string object .

The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=12257

For more information, refer to: http://www.softwhy.com/javascript/

JS implementation of random output uppercase and lowercase letters code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.