introducing few game utils

This commit is contained in:
Antoine M 2024-02-13 19:25:48 +01:00
parent ca8184c7a6
commit 5fae2a54b3

View File

@ -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 };