Hello everyone, I’m sure this is a stupid question but when I was working on Missing Letters Challenge and try to return String.fromCharCode(value) doesn’t work but if I storage the return from String.fromCharCode(value) in a variable and then return the variable, work. My question is, Can somebody explain to me why??? Thanks!!!
This code work:
function fearNotLetter(str) {
var missingLetter;
var inputLetterRange = str.split('');
var asciiInputLetterRange = inputLetterRange.map(function(letter){
return letter.charCodeAt();
});
asciiInputLetterRange.forEach(function(letterValue, index, asciiInputLetterRange){
if (index < asciiInputLetterRange.length - 1){
if (letterValue != asciiInputLetterRange[index + 1] - 1){
missingLetter = String.fromCharCode(letterValue + 1);
}
}
});
return missingLetter;
}
fearNotLetter("abce");
return “d”;
This doesn’t pass the test and return is empty in the codemirror.
function fearNotLetter(str) {
var inputLetterRange = str.split('');
var asciiInputLetterRange = inputLetterRange.map(function(letter){
return letter.charCodeAt();
});
asciiInputLetterRange.forEach(function(letterValue, index, asciiInputLetterRange){
if (index < asciiInputLetterRange.length - 1){
if (letterValue != asciiInputLetterRange[index + 1] - 1){
return String.fromCharCode(letterValue + 1);
}
}
});
return undefined;
}
fearNotLetter("abce");
Thanks!!!