add eraser button and add start calculation logic

This commit is contained in:
Suvodip
2024-09-06 20:05:34 +05:30
parent 2fe965cd99
commit d2a1edd333
21 changed files with 291 additions and 139 deletions

View File

@@ -79,9 +79,9 @@ import Layout from "../../layouts/Layout.astro";
<input onclick="checkResult2('image6');" type="checkbox" id="a6" class="round-checkbox-input myCheckbox largerCheckbox" value="a6"/>
</div>
</div>
<div class="flex flex-col place-items-center justify-center pt-8">
<div class="flex flex-col justify-center place-items-center pt-8">
<p class="text-[20px] font-[600] text-[#FF0000] px-[20px] py-[10px]" style="display: none;" id="errorMessage">Please select at least 3 options.</p>
<p class="text-[20px] font-[600] text-[#FFFFFF] bg-[#004aad] px-[20px] py-[10px]" style="display: none;" id="savedMessage"></p>
<!-- <input onclick="saveUserData();" class="bg-blue-700 px-8 py-2 rounded-lg shadow-lg font-bold text-white cursor-pointer" type="submit" value="Submit"> -->
</div>
</form>
</div>
@@ -92,9 +92,15 @@ import Layout from "../../layouts/Layout.astro";
<script is:inline>
const params = new URLSearchParams(window.location.search);
const gameId = params.get('id');
const userId = params.get('userid');
const userId = params.get('userId');
let startTime = Date.now();
let gameData = null;
let wrongCount = 0;
let starValue;
let totalPoints = 0;
let url = window.location.href;
let urlSplit = url.split('/');
let gameName = urlSplit[3] + '-' + urlSplit[4].split('?')[0];
fetch(`https://game-du.teachertrainingkolkata.in/items/tick_phonics_option_6/${encodeURIComponent(gameId)}?filter[status][_eq]=published`)
.then(res => res.json())
@@ -144,17 +150,26 @@ import Layout from "../../layouts/Layout.astro";
element.classList.remove('greenBorder', 'redBorder');
}
}
let url = window.location.href;
let urlSplit = url.split('/');
let gameName = urlSplit[3] + '-' + urlSplit[4];
function saveUserData() {
const checkboxes = ['a1', 'a2', 'a3', 'a4', 'a5', 'a6'];
const checkedCount = checkboxes.filter(id => document.getElementById(id).checked).length;
if (checkedCount < 2) {
// Show error message if less than 3 checkboxes are checked
let errorMessageSection = document.getElementById('errorMessage');
errorMessageSection.style.display = "block";
errorMessageSection.innerHTML = 'Please select at least 2 options.';
return;
} else {
// Hide error message if validation passes
let errorMessageSection = document.getElementById('errorMessage');
errorMessageSection.style.display = "none";
}
const endTime = Date.now();
const timeDifference = endTime - startTime;
const timeDifferenceInSeconds = timeDifference / 1000;
// Get checkbox values and corresponding elements
const checkboxes = ['a1', 'a2', 'a3', 'a4', 'a5', 'a6'];
const checkboxValues = checkboxes.map(id => {
const checkbox = document.getElementById(id);
const element = document.getElementById('image' + id.slice(-1));
@@ -166,7 +181,6 @@ import Layout from "../../layouts/Layout.astro";
});
// Count points based on checkbox values and "greenBorder" class
let totalPoints = 0;
checkboxValues.forEach(checkbox => {
if (checkbox.checked && checkbox.element.classList.contains('greenBorder')) {
totalPoints += 1;
@@ -174,12 +188,15 @@ import Layout from "../../layouts/Layout.astro";
});
// Move the userData object creation inside the saveUserData function if needed
wrongCount === 0 ? starValue = 5 : wrongCount === 1 ? starValue = 4 : starValue = 3;
let userData = {
'gameName': gameName,
'gameID': gameId,
'userId': userId,
'gameTime': timeDifferenceInSeconds,
'score': totalPoints,
'star': starValue
};
// console.log(userData);
fetch(`https://api.teachertrainingkolkata.in/api/saveGameScore`, {