This commit is contained in:
Suvodip
2025-01-26 13:45:25 +05:30
parent f15a4b3b27
commit 54f2c9f06e
11 changed files with 247 additions and 177 deletions

View File

@@ -153,7 +153,7 @@ import Layout from "../../layouts/Layout.astro";
let maxScore = 6;
let progress = 0;
const progressBar = document.createElement('div');
let totalCorrectFromApi = 0;
fetch(`https://game-du.teachertrainingkolkata.in/items/cross_phonics_option_6/${encodeURIComponent(gameId)}?filter[status][_eq]=published`)
.then(res => res.json())
.then(data => {
@@ -285,17 +285,25 @@ import Layout from "../../layouts/Layout.astro";
totalPoints += 1;
}
});
let starValue = Math.round((totalPoints / maxScore) * 10);
starValue = starValue === 0 ? 3 : starValue;
const answersList = ['a1', 'a2', 'a3', 'a4', 'a5', 'a6'];
answersList.forEach((answer) => {
if (gameData[answer] === true) {
totalCorrectFromApi++;
}
});
let afterNegative = totalPoints - wrongCount;
let percentage = Math.round((afterNegative / totalCorrectFromApi ) * 10);
if(percentage <= 3){
percentage = 3
}
let feedbackMessage = '';
if (starValue >= 1 && starValue <= 3) {
if (percentage >= 1 && percentage <= 3) {
feedbackMessage = "You're making progress! Let's keep going!";
} else if (starValue >= 4 && starValue <= 6) {
} else if (percentage >= 4 && percentage <= 6) {
feedbackMessage = "Nice work! You're improving every day!";
} else if (starValue >= 7 && starValue <= 8) {
} else if (percentage >= 7 && percentage <= 8) {
feedbackMessage = "Amazing work! Keep it up!";
} else if (starValue >= 9 && starValue <= 10) {
} else if (percentage >= 9 && percentage <= 10) {
feedbackMessage = "Outstanding! You're a true superstar!";
} else {
feedbackMessage = "Invalid star value.";
@@ -416,7 +424,7 @@ import Layout from "../../layouts/Layout.astro";
'userId': userId,
'gameTime': timeDifferenceInSeconds,
'score': totalPoints,
'gameStar': starValue
'gameStar': percentage
};
fetch(`https://api.teachertrainingkolkata.in/api/saveGameScore2`, {
method: 'POST',
@@ -436,7 +444,7 @@ import Layout from "../../layouts/Layout.astro";
starContainer.style.display = 'flex';
starContainer.style.flexDirection = 'row';
document.getElementById('starFeedbackMessage').innerHTML = feedbackMessage;
document.getElementById('get-star-value').innerHTML = starValue;
document.getElementById('get-star-value').innerHTML = percentage;
scoreBoard.style.display = 'flex';
}
} else {