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

@@ -129,15 +129,14 @@ import Layout from "../../layouts/Layout.astro";
const worksheetId = params.get('worksheetId');
let startTime = Date.now();
let gameData = null;
let starValue;
let url = window.location.href;
let urlSplit = url.split('/');
// let gameName = urlSplit[3] + '-' + urlSplit[4].split('?')[0];
let totalPoints = 0;
let maxScore = 3;
let wrongCount = 0;
let progress = 0;
const progressBar = document.createElement('div');
let totalCorrectFromApi = 0;
function showClipArt() {
const clipArtContainer = document.querySelector('.clip-art-container');
clipArtContainer.classList.remove('hidden');
@@ -223,9 +222,10 @@ import Layout from "../../layouts/Layout.astro";
element.classList.add('greenBorder');
} else {
element.classList.add('redBorder');
wrongCount += 1;
}
} else {
wrongCount -= 1;
wrongCount += 1;
element.classList.remove('greenBorder', 'redBorder');
}
}
@@ -254,19 +254,30 @@ 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'];
answersList.forEach((answer) => {
if (gameData[answer] === true) {
totalCorrectFromApi++;
}
});
let afterNegative = totalPoints - wrongCount;
let percentage = Math.round((afterNegative / totalCorrectFromApi ) * 10);
percentage = Math.max(3, Math.min(percentage, 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) {
feedbackMessage = "Nice work! You're improving every day!";
} else if (starValue >= 7 && starValue <= 8) {
feedbackMessage = "Amazing work! Keep it up!";
} else if (starValue >= 9 && starValue <= 10) {
feedbackMessage = "Outstanding! You're a true superstar!";
} else if (percentage >= 4 && percentage <= 6) {
feedbackMessage = "Nice work! You're improving every day!";
} else if (percentage >= 7 && percentage <= 8) {
feedbackMessage = "Amazing work! Keep it up!";
} else if (percentage >= 9 && percentage <= 10) {
feedbackMessage = "Outstanding! You're a true superstar!";
} else {
feedbackMessage = "Invalid star value.";
feedbackMessage = "Invalid star value.";
}
progressIncrement();
@@ -382,7 +393,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',
@@ -401,7 +412,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 {