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