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 points, we first find the time difference in milliseconds between the time the note hit the bottom of the panel and the...