Letter Lookup explainer

Aim of the puzzle: Write a function that takes a string and an object map of a string, and returns true if all of the letters of the string exist in the object, or false if they do not.
Walk through of solution: In a later puzzle, you will write a function that checks if a string is a subsequence of another string. For now, write a function that simply checks if all of the letters in one string exist in the other.

In the last puzzle, you wrote a function that turns a string into an object map. The output of that function will be used as input for this function.

To start, add a for loop to iterate through the input string. For example:

for (let letter of word) {

}

Then, add an if else statement that checks if a property with the name of the current character exists in the map. If a letter is found, the function does not need to do anything, but if the letter is not found, the function should return false. It should look something like this:

for (let letter of word) {
 if (map[letter] {
  
  } else {
    return false;
  }
}

At the end of the function, return true.

return true;

This line of code will only run if the function iterates through the entire string without returning false for any of the letters.
Javascript Concepts: Functions, Objects, Strings, Properties, For Loops, If Statements, Bracket Notation, Truthy and Falsy
Additional Code (hidden code that runs before the puzzle’s code):

let dictionaryWord = pickRandom([ 'able', 'peals', 'bale', 'kangaroo']);

let stringSequence = {
            a:[0],
            b: [1],
            p:[2,3,4],
            l:[5],
            e:[6,7]
        };

const makeMap = (o) => {
   var out = '';
   for (var p in o) {
      out += p + ': ' + '[' +  o[p] + ']' + ', ' ;
      console.log(out);
      out = ''
   }
   return o
};


What am I doing wrong

Hey there,

The function declaration has 2 parameters: word and object

object represents the string that has been mapped to an object. word is the string we want to compare it with.

In your if statement, you are using the string 'map' instead of the object parameter.

Try replacing the string 'map' with the identifier object (it will be its own key on the keyboard, so you won’t have to type it).

Hope this helps! Let me know if you have any questions.
-Ben

1 Like