gpt4 book ai didi

Javascript charCodeAt() 没有返回正确的代码..或者是吗?

转载 作者:行者123 更新时间:2023-11-28 19:36:24 25 4
gpt4 key购买 nike

我正在尝试查找键码(如果这正是我需要的)并将字符更改为递增的键码(这只是为了编码挑战),但它不起作用

function LetterChanges(str) { 
var newString = "";
var keyCode;
for(var i = 0; i < str.length; ++i)
{

keyCode = str.charCodeAt(i);
console.log(keyCode);
if( keyCode > 57 && keyCode < 122)
{

//add 1 to the keycode

newString += String.fromCharCode(i+1);
//console.log(String.fromCharCode(i+1));

}
else if(keyCode === 90)
{
//if it's a z being examined, add an a
newString += "a";
}
else
//it is a symbol, so just add it to the new string without change
newString += str[i];
}
return newString.toUpperCase();

}

console.log(LetterChanges("Charlie"));

最佳答案

改变

newString += String.fromCharCode(i+1);

newString += String.fromCharCode(keyCode+1);

关于Javascript charCodeAt() 没有返回正确的代码..或者是吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25800237/

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