Chords

Beej is learning to play the guitar. He’s not very good yet so he needs so help learning the notes in a chord. In music there are 7 lettered notes and 5 half steps between notes creating a 12 note scale. Chords are composed of three or more notes starting with the note the chord is named after. For the major chords the notes are the 1st (the name of the chord), 3rd, and 5th notes.

The Challenge

For this challenged create an app that takes in the name of the chord and returns the three notes that compose it. So if ‘G’ is entered ‘G, B, D’ will be returned. This also applies to sharps (#)and flats (b) so ‘D#’ will return ‘D#, F#, A#’.

Hint: There are two sets of notes that do not have a half step between them: B-C and E-F. For these if it is a sharp move up a to the full note and if flat stay at the lower note.

Creating a Test Case

We’ll continue to use test driven development. No matter the level you choose write a test case before you start coding. Then write enough code to pass the test. Once you have a passing test write more tests and refactor you code to accommodate all possible tests.

A Step Further

Going a step further, add in the option to return the minor chord. The minor chords are the same as the major except that the 3rd note is a half step down. So the ‘G’ minor chord contains the notes ‘G, Bb, D’. For sharps and flats the same applies so ‘Gb’ minor chord contains notes ‘Gb, A, Db’.

Hint: There are two sets of notes that do not have a half step between them: B-C and E-F. So instead of moving a half step you move a full step down.