JavaScript 代码不工作,没有错误或停止
JavaScript code doesn't work, no errors or stops
我是 JavaScript 的新手,我尝试编写凯撒密码的解码器。但是我的代码不起作用,没有显示任何错误,也没有停止。
let word = "привет";
let shift = 3;
let result = "";
for (let i = 0; i < word.legth; i++){
if ('А'.charCodeAt(0) <= word[i].charCodeAt(0) <= 'Я'.charCodeAt(0)) {
let char = ((word[i].charCodeAt(0) + shift - 'А'.charCodeAt(0)) % 32) + 'А'.charCodeAt(0)
result = result + String.fromCharCode(char);
}
else if ('а'.charCodeAt(0) <= word[i].charCodeAt(0) <= 'я'.charCodeAt(0)) {
let char = ((word[i].charCodeAt(0) + shift - 'а'.charCodeAt(0)) % 32) + 'а'.charCodeAt(0)
result = result + String.fromCharCode(char);
}
else {
result = result + word[i];
}
}
console.log(result)
将word.legth更改为word.length
let word = 'привет';
let shift = 3;
let result = '';
for (let i = 0; i < word.length; i++) {
if ('А'.charCodeAt(0) <= word[i].charCodeAt(0) <= 'Я'.charCodeAt(0)) {
let char =
((word[i].charCodeAt(0) + shift - 'А'.charCodeAt(0)) % 32) +
'А'.charCodeAt(0);
result = result + String.fromCharCode(char);
} else if (
'а'.charCodeAt(0) <=
word[i].charCodeAt(0) <=
'я'.charCodeAt(0)
) {
let char =
((word[i].charCodeAt(0) + shift - 'а'.charCodeAt(0)) % 32) +
'а'.charCodeAt(0);
result = result + String.fromCharCode(char);
} else {
result = result + word[i];
}
}
console.log(result);
我是 JavaScript 的新手,我尝试编写凯撒密码的解码器。但是我的代码不起作用,没有显示任何错误,也没有停止。
let word = "привет";
let shift = 3;
let result = "";
for (let i = 0; i < word.legth; i++){
if ('А'.charCodeAt(0) <= word[i].charCodeAt(0) <= 'Я'.charCodeAt(0)) {
let char = ((word[i].charCodeAt(0) + shift - 'А'.charCodeAt(0)) % 32) + 'А'.charCodeAt(0)
result = result + String.fromCharCode(char);
}
else if ('а'.charCodeAt(0) <= word[i].charCodeAt(0) <= 'я'.charCodeAt(0)) {
let char = ((word[i].charCodeAt(0) + shift - 'а'.charCodeAt(0)) % 32) + 'а'.charCodeAt(0)
result = result + String.fromCharCode(char);
}
else {
result = result + word[i];
}
}
console.log(result)
将word.legth更改为word.length
let word = 'привет';
let shift = 3;
let result = '';
for (let i = 0; i < word.length; i++) {
if ('А'.charCodeAt(0) <= word[i].charCodeAt(0) <= 'Я'.charCodeAt(0)) {
let char =
((word[i].charCodeAt(0) + shift - 'А'.charCodeAt(0)) % 32) +
'А'.charCodeAt(0);
result = result + String.fromCharCode(char);
} else if (
'а'.charCodeAt(0) <=
word[i].charCodeAt(0) <=
'я'.charCodeAt(0)
) {
let char =
((word[i].charCodeAt(0) + shift - 'а'.charCodeAt(0)) % 32) +
'а'.charCodeAt(0);
result = result + String.fromCharCode(char);
} else {
result = result + word[i];
}
}
console.log(result);