play plays notes

play will sound out a sequence of musical notes.

play "GEC"

The notes are written in standard ABC notation, which uses the capital letter "C" for middle C. In ABC notation, the C major scale can be written "CDEFGABC'".

Read about pitch, sharps, flats, beats, rests, and chords in ABC notation.


Put all the notes inside quotes. Quotation marks are used to separate the music written in ABC notation from the code that plays the whole piece of music.


Triple quotes """ separate a large piece of music from the rest of the code.

To play a longer song that fills up more than one line of code, use triple-quotes.

play """
  F ^G C' F'
  [=G'E] C' ^G
  =G' [^G'^D] C'
  ^G ^G' [=D'D]
  ^A F D'
  [^C=C'] ^G F
  ^G21/3 C' ^G F

Triple quotes must match, just like regular quotes. Put a triple quote before the first line of music, and then put one after the last line of music.


play accepts an optional options object as a first argument:

play {tempo: 200},

Options include: