s5
This commit is contained in:
@@ -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/game_cross_varient1/${encodeURIComponent(gameId)}?filter[status][_eq]=published`)
|
||||
.then(res => res.json())
|
||||
@@ -288,16 +288,26 @@ import Layout from "../../layouts/Layout.astro";
|
||||
}
|
||||
});
|
||||
|
||||
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.";
|
||||
@@ -418,7 +428,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',
|
||||
@@ -438,7 +448,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 {
|
||||
|
||||
Reference in New Issue
Block a user