gpt4 book ai didi

javascript - 从 a-z 中选择一个随机字母

转载 作者:行者123 更新时间:2023-12-01 00:40:25 25 4
gpt4 key购买 nike

How do I choose a random letter from a-z and put it into a heading in my html by itself and make it replace any other letter that was there before? I don't know if what I've done works.

function randLetter( ) {

var letters =
("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q"
,"r","s","t","u","v","w","x","y","z");

var letter = letters[Math.floor(Math.random()*letters.length)];

return letter

}

$('#letter').html('letter')

最佳答案

对于大写字母,您可以使用

String.fromCharCode(65+Math.floor(Math.random() * 26))

对于小写字母

String.fromCharCode(97+Math.floor(Math.random() * 26))

关于javascript - 从 a-z 中选择一个随机字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29505419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com