Tell us what’s happening:
First help post, sorry if it isn’t formatted correctly.
I am not sure why I can’t return undefined with this && condition? I found some of the other solutions on the forums but want to understand why this, in particular, doesn’t work.
Otherwise the missing checker is working correctly.
Thanks for the advice!
Your code so far
function fearNotLetter(str) {
let charCodeArr = [];
for (let i = 0; i < str.length; i++) {
charCodeArr.push(str.charCodeAt([i]))
}
for(var i = 1; i < charCodeArr.length; i++) {
if (charCodeArr[i] - charCodeArr[i-1] != 1) {
let missingNum = charCodeArr[i] - 1;
return String.fromCharCode(missingNum)
}
else if (charCodeArr[i] - charCodeArr[i-1] == 1 && charCodeArr[i] - charCodeArr[i-1] != 2) {
return undefined;
}
}
return str;
}
fearNotLetter("abce");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/missing-letters/