Task 4: Transform the Object

  1. Write the rest of the transform() function. It will need to take an object as a parameter - specifically the oldPointStructure object. Calling transform(oldPointStructure) will return an object with lowercase letters as keys. The value for each key will be the points assigned to that letter.

    Tip
    1. Recall that for...in loops iterate over the keys within an object.

    2. If you need a reminder of how to assign new key/value pairs, review the relevant section in the Objects and Math chapter.

    3. To access the letter arrays within oldPointStructure, use bracket notation (oldPointStructure[key]).

    4. To access a particular element within a letter array, add a second set of brackets (oldPointStructure[key][index]), or assign the array to a variable and use variableName[index].

      1
      2
      3
      4
      5
      6
      
      console.log("Letters with score '4':", oldPointStructure[4]);
      console.log("3rd letter within the key '4' array:", oldPointStructure[4][2]);
      
      let letters = oldPointStructure[8];
      console.log("Letters with score '8':", letters);
      console.log("2nd letter within the key '8' array:", letters[1]);
      

      Console Output

      Letters with score '4': [ 'F', 'H', 'V', 'W', 'Y' ]
      3rd letter within the key '4' array: V
      
      Letters with score '8': [ 'J', 'X' ]
      2nd letter within the key '8' array: X
      
  2. Locate the newPointStructure object in the starter code and set it equal to transform(oldPointStructure).

    Warning

    Hard-coding the newPointStructure object literal like this:

    let newPointStructure = 
    {
       a:1,
       b: 1,
       c: 1,
       etc ...
    }
    

    won’t pass. And you’ll lose an opportunity to practice this skill.

  3. Once you’ve defined newPointStructure, use it to finish writing the scrabbleScorer() function and then replace the oldScrabbleScorer() function in scoringAlgorithms with this new function.

    Tip

    oldScrabbleScorer() uses oldPointStructure and returns a score for each letter in a word. You’ll want to write scrabbleScorer() to use newPointStructure and return a cumulative score for the whole word entered.