diff --git a/src/utils/gameFunctions.js b/src/utils/gameFunctions.js new file mode 100644 index 0000000..4871bd2 --- /dev/null +++ b/src/utils/gameFunctions.js @@ -0,0 +1,20 @@ +function calculateScore(answers) { + const correctAnswers = answers.filter((answer) => answer.userAnsweredCorrectly === true); + const score = correctAnswers.length; + return score; +} +function formatCurrentTime(currentTime) { + // Minutes calculation + const minutes = Math.floor((currentTime % 360000) / 6000) + .toString() + .padStart(2, "0"); + + // Seconds calculation + const seconds = Math.floor((currentTime % 6000) / 100) + .toString() + .padStart(2, "0"); + + return `${minutes} : ${seconds}`; +} + +export { calculateScore, formatCurrentTime }; \ No newline at end of file