我肯定错过了什么。
在下面的代码中,我清楚地声明loopingAdjustment,然后在它下面我在fromCharCode函数中调用它。所以,我正在使用它,对吧?我应该可以调用它,因为它在同一个范围内,对吧?
为什么 VSCode 说它“从未使用过”,为什么我的终端说它“未定义”?
谢谢你。
const caesar = function(startingString, shiftAmount) {
let itemizedString = startingString.split('');
const mappedLetters = itemizedString.map(stringLetter => {
//turn each letter in array into their respective character code
let thisLetter = stringLetter.charCodeAt(stringLetter);
// checking if character is alphabetic and converting its charcode back to a letter
if (thisLetter < 65 || (thisLetter > 90 && thisLetter < 97) || thisLetter > 122) {
return;
} else {
shiftedLetter = thisLetter + shiftAmount;
}
// making sure the shifted letters loop to beginning, or end, of alphabet
if (thisLetter > 96 && shiftedLetter > 122) {
let loopingAdjustment = shiftedLetter - 26;
} else if (thisLetter > 96 && shiftedLetter < 96) {
let loopingAdjustment = shiftedLetter + 26;
} else if (thisLetter < 91 && shiftedLetter > 90) {
let loopingAdjustment = shiftedLetter - 26;
} else if (thisLetter < 91 && shiftedLetter < 65) {
let loopingAdjustment = shiftedLetter + 26;
} else {
let loopingAdjustment = shiftedLetter;
}
let finalString = String.fromCharCode(loopingAdjustment);
return finalString;
});
console.log(mappedLetters);
return mappedLetters.join('');
}
module.exports = caesar
慕莱坞森
开心每一天1111
相关分类