I was having a difficult time debugging this, when I discovered that the variable i here was being treated as a string. Therefore, i+1 concatenated the numbers instead of adding. Why is this?
function fearNotLetter(str) {
if(str.charCodeAt(str.length-1)-str.charCodeAt(0)===str.length-1){
return undefined;
}
for(let i in str){
console.log(str.charCodeAt(i))
console.log(i+1)
console.log(str.charCodeAt(i+1))
if(str.charCodeAt(i+1)-str.charCodeAt(i)===2){
return String.fromCharCode(str.charCodeAt(i)+1);
}
}
return str;
}
function fearNotLetter(str) {
if(str.charCodeAt(str.length-1)-str.charCodeAt(0)===str.length-1){
return undefined;
}
for(let i in str){
console.log(str.charCodeAt(i))
console.log(i+1)
console.log(str.charCodeAt(i+1))
if(str.charCodeAt(i+1)-str.charCodeAt(i)===2){
return String.fromCharCode(str.charCodeAt(i)-1);
}
}
//return str;
}
console.log(fearNotLetter("abcdefghjklmno"));
**Your browser information:**
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0
Challenge: Missing letters
Link to the challenge: