Skip to content

Commit

Permalink
Load the correct sound only once.
Browse files Browse the repository at this point in the history
  • Loading branch information
arfurlaneto committed Aug 28, 2015
1 parent 4fdac4f commit 98f3075
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion js/mathtrainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
result: 0
};

/**
* Audio to play on correct answers.
*/
var correctAudio = new Audio('correct.mp3');

/** Trainer logic. */
var trainer = {};

Expand Down Expand Up @@ -125,7 +130,8 @@
var userResult = parseInt($('#result').val());
if (!isNaN(userResult) && userResult === question.result) {
++stats.total;
(new Audio('correct.mp3')).play();
correctAudio.currentTime = 0;
correctAudio.play();
createNew();
}
};
Expand Down

0 comments on commit 98f3075

Please sign in to comment.