add eraser button and add start calculation logic
This commit is contained in:
@@ -17,13 +17,8 @@ import Layout from "../../layouts/Layout.astro";
|
||||
<button><img src="/assets/svg/cancel.svg" alt=""></button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- <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>
|
||||
<div class="container mx-auto px-4">
|
||||
<!-- <div class="flex flex-col">
|
||||
<p id="LearningArea"></p>
|
||||
<p id="LearningSubArea_copy"></p>
|
||||
</div> -->
|
||||
<p class="sm:text-2xl md:text-3xl lg:text-3xl text-center font-[600] text-[#60C6CB] my-4 select-none" id="gameDescription"></p>
|
||||
<form id="contactForm">
|
||||
<div id="" class="flex flex-row place-content-between ">
|
||||
@@ -86,8 +81,8 @@ import Layout from "../../layouts/Layout.astro";
|
||||
</div>
|
||||
</div>
|
||||
<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>
|
||||
@@ -98,9 +93,16 @@ 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 wrongCount = 0;
|
||||
let url = window.location.href;
|
||||
let urlSplit = url.split('/');
|
||||
let gameName = urlSplit[3] + '-' + urlSplit[4].split('?')[0];
|
||||
let maxPoint = 9;
|
||||
let starValue;
|
||||
let totalPoints = 0;
|
||||
|
||||
fetch(`https://game-du.teachertrainingkolkata.in/items/game_cross_varient2/${encodeURIComponent(gameId)}?filter[status][_eq]=published`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
@@ -134,15 +136,13 @@ import Layout from "../../layouts/Layout.astro";
|
||||
if(gameData.label9){
|
||||
document.getElementById("label9").innerHTML = gameData.label9;
|
||||
}
|
||||
// document.getElementById('LearningArea').innerHTML = gameData.LearningArea;
|
||||
// document.getElementById('LearningSubArea_copy').innerHTML = gameData.LearningSubArea_copy;
|
||||
const assetsURL = 'https://game-du.teachertrainingkolkata.in/assets/';
|
||||
for (let i = 1; i <= 9; i++) {
|
||||
const imageId = `image${i}`;
|
||||
document.getElementById(imageId).src = assetsURL + gameData[imageId];
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
function checkResult2(id) {
|
||||
const checkbox = document.getElementById('a' + id.slice(-1));
|
||||
const element = document.getElementById(id);
|
||||
@@ -152,33 +152,35 @@ import Layout from "../../layouts/Layout.astro";
|
||||
element.classList.add('redBorder');
|
||||
} else {
|
||||
element.classList.add('greenBorder');
|
||||
wrongCount +=1;
|
||||
}
|
||||
} else {
|
||||
element.classList.remove('redBorder', 'greenBorder');
|
||||
}
|
||||
// console.log(wrongCount)
|
||||
}
|
||||
|
||||
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', 'a7', 'a8', 'a9'];
|
||||
const checkedCount = checkboxes.filter(id => document.getElementById(id).checked).length;
|
||||
|
||||
if (checkedCount < 3) {
|
||||
// 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 3 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;
|
||||
|
||||
// const checkboxValues = {
|
||||
// a1: document.getElementById('a1').checked,
|
||||
// a2: document.getElementById('a2').checked,
|
||||
// a3: document.getElementById('a3').checked,
|
||||
// a4: document.getElementById('a4').checked,
|
||||
// a5: document.getElementById('a5').checked,
|
||||
// a6: document.getElementById('a6').checked,
|
||||
// a7: document.getElementById('a7').checked,
|
||||
// a8: document.getElementById('a8').checked,
|
||||
// a9: document.getElementById('a9').checked,
|
||||
// };
|
||||
const checkboxes = ['a1', 'a2', 'a3', 'a4', 'a5', 'a6', 'a7', 'a8', 'a9'];
|
||||
const checkboxValues = checkboxes.map(id => {
|
||||
const checkbox = document.getElementById(id);
|
||||
const element = document.getElementById('image' + id.slice(-1));
|
||||
@@ -189,21 +191,24 @@ 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('redBorder')) {
|
||||
totalPoints += 1;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
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`, {
|
||||
method: 'POST',
|
||||
@@ -220,7 +225,7 @@ import Layout from "../../layouts/Layout.astro";
|
||||
savedMessageSection.innerHTML = 'Saved Successfully';
|
||||
}
|
||||
} else {
|
||||
// console.log('Something Wrong', response);
|
||||
// Handle error
|
||||
}
|
||||
})
|
||||
.catch(error => {
|
||||
@@ -228,6 +233,7 @@ import Layout from "../../layouts/Layout.astro";
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const contactForm = document.getElementById('contactForm');
|
||||
contactForm.addEventListener('submit', async function (event) {
|
||||
|
||||
Reference in New Issue
Block a user