Tell us what’s happening:
I can’t seem to able to return undefined when there is no missing letter.
I created an array from the string so that it’s values can act like a counter using forEach.
I then looped through checking the unicode for each letter and subtracting it from the next one.
If the difference between the two is more than 1, I add a single digit to the unicode of the previous character so that I can then convert it back to a letter.
I then set str to the letter after conversion and returned it.
Problem is I can’t figure out the case for returning undefined when no letters are missing.
Your code so far
function fearNotLetter(str) {
let strA = str.split('');
strA.forEach(x => {
if(str.charCodeAt(str.indexOf(x)+1) - str.charCodeAt(str.indexOf(x)) > 1){
str = String.fromCharCode(str.charCodeAt(str.indexOf(x))+1);
}
else{
str = undefined;
}
});
console.log(str);
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/70.0.3538.110 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/missing-letters