Home > Web Front-end > JS Tutorial > How to generate random uppercase and lowercase letters in javascript_javascript tips

How to generate random uppercase and lowercase letters in javascript_javascript tips

WBOY
Release: 2016-05-16 16:59:01
Original
1967 people have browsed it
复制代码 代码如下:

/**
* returns a random lowercase letter
*/
function getLowerCharacter(){
return getCharacter("lower");;
}


/**
* returns a random uppercase letter
*/
function getUpperCharacter(){
return getCharacter("upper");;
}


/**
* returns a letter
*/
function getCharacter(flag){
var character = "";
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));
}
return character;
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template