From 5fae2a54b32adf445cfec8959e2deab0007a3d18 Mon Sep 17 00:00:00 2001 From: Antoine M Date: Tue, 13 Feb 2024 19:25:48 +0100 Subject: [PATCH] introducing few game utils --- src/utils/gameFunctions.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/utils/gameFunctions.js 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