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
WBOYOriginal
2016-05-16 16:59:011963browse
复制代码 代码如下:

/**
* 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;
}
Statement:
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