Time for action – checking the notes

We will add a call to the checkNote() method in the keyDown() method. The checkNote() method takes the name of the note as a parameter, and checks if there is a note element at the bottom of the notes panel that matches it:

function checkNote(note)
{
    if (currentNote.note == note)
    {
        var dif = getCurrentTime() - currentNote.time;
        if (dif < gracePeriod)
        {
            notesCorrect++;
            score += Math.round(10 * (gracePeriod - dif) / gracePeriod);
            currentNote.$note.css("background", "green");
            addHitEffect();
        }
    }
}

First we check the currentNote object that was set previously in updateNotes() . If its note is the same as the one the user played, then they might get some points for playing it at the correct time. To find out if they ...

Get HTML5 Web Application Development By Example Beginner's guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.