Drag the edges to resize the window.

In Projects, you can keep track of your progress as you go throught the tasks. Check each item as you complete it!

Code Editor
Learn TDD With Mocha

Red to Green II

Once we have multiple tests, it pushes us to write implementation code that more fully encompasses our desired behavior. Though it still may not execute the final intended behavior, implementation code that passes multiple tests will be closer to the final behavior.

Let's think about the current state of our Phrase.initials method. We have one passing test and one failing test that raises the following error when you run the test suite:

1) Phrase .initials should return the first letter of each word in a phrase:

1) AssertionError: 'JMS' == 'NM'
+ expected - actual
   - 'NM'
   + 'JMS'

This is because the following implementation returns 'NM' when we pass in 'Juan Manuel Santos':

const Phrase = { initials(inputName) { return 'NM'; } }

This is not surprising, considering our current implementation always returns 'NM.'

To write a more complete implementation, that could get us back into the green, we could write something like this:

const Phrase = { initials(inputName) { const initials = []; const words = inputName.split(" "); words.forEach((word) => { initials.push(word.charAt(0)); }); return initials.join(""); } }

This implementation returns the initials of a string input.

Each additional test pushes us to build a more complete implementation of the .initials method.

Report a Bug
If you see a bug or any other issue with this page, please report it here.