introducing few game utils
This commit is contained in:
parent
ca8184c7a6
commit
5fae2a54b3
20
src/utils/gameFunctions.js
Normal file
20
src/utils/gameFunctions.js
Normal 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 };
|
||||
Loading…
Reference in New Issue
Block a user