Missing Letter - Help needed


New to posting so sorry if this is in the wrong place!
I am looking for help, my code so far for the missing letters challenge doesnt work and I cant work out why.
I have it returning the missing letter in a string of letters when it passes a test in a map function but also returning ‘undefined’ when my test for the missing letter isnt passed, I dont know how to stop this?

(I know there are easier ways to do this having looked at the hints but would appreciate understanding why my way doesnt work)

Your code so far

function fearNotLetter(str) {
let fear = {

let str1=str.split("");

return str1.map(function(val,index,array){ 

if((fear[val])!== (fear[array[index+1]]-1) && (str1.length-1>index)) 
{return String.fromCharCode(val.charCodeAt()+1)}
else return;



Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36.

Challenge: Missing letters

Link to the challenge:

Hello and welcome to the forum :partying_face:!

I checked Your code and it works almost as expected.

Your main problem is that the code must return a single letter or undefined, whereas now You’re returning an array which may have only null values:

// Your current output for a string 'abce':
[ null, null, null, 'd', null]

// The expected output for the same string:

// Your output for the string 'abc':
[ null, null, null ]

// The expected output:

Basically, You need to iterate the resulting map and remove all the null values. If there are only nulls, then return undefined.

Hope it helps (I’m not giving You the answer yet :stuck_out_tongue:) ,


1 Like

Thanks that makes a lot of sense!

I see what you mean about returning an array and not a single answer.

I will try again , Thanks :smile:

1 Like