Skip to content

Commit

Permalink
Merge pull request #57 from avanimathur/main
Browse files Browse the repository at this point in the history
Update Scoring System Based on Response Time Interval
  • Loading branch information
Akanchha112 authored Jan 15, 2024
2 parents 5035d68 + 3acc5b8 commit e63e609
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 10 deletions.
20 changes: 15 additions & 5 deletions Dark/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const time_line = document.querySelector(".time .time_line");
const timeText = document.querySelector(".timer .time_left_txt");
const timeCount = document.querySelector(".timer .timer_sec");


var soundCorrect = new Audio("sounds/correctAns.mp3");
var soundIncorrect = new Audio("sounds/wrongAns.mp3");
var myMusic = new Audio("sounds/gametheme.mp3");
Expand All @@ -26,7 +25,6 @@ let widthValue = 0;

let questions = [];


fetch(
'https://opentdb.com/api.php?amount=10&category=17&difficulty=easy&type=multiple'
)
Expand Down Expand Up @@ -60,7 +58,7 @@ fetch(
console.error(err);
});

//CONSTANTS
// CONSTANTS
const CORRECT_BONUS = 10;
const MAX_QUESTIONS = 10;

Expand Down Expand Up @@ -124,8 +122,18 @@ choices.forEach((choice) => {
clearInterval(counter);
clearInterval(counterLine);

const timeRemaining = parseInt(timeCount.textContent);

if (classToApply === 'correct') {
incrementScore(CORRECT_BONUS);
let scoreToAdd = 0;
if (timeRemaining > 10 && timeRemaining <= 15) {
scoreToAdd = 10;
} else if (timeRemaining > 5 && timeRemaining <= 10) {
scoreToAdd = 5;
} else if (timeRemaining > 0 && timeRemaining <= 5) {
scoreToAdd = 2;
}
incrementScore(scoreToAdd);
soundCorrect.play();
} else {
soundIncorrect.play();
Expand All @@ -143,7 +151,8 @@ choices.forEach((choice) => {
function startTimer(time) {
counter = setInterval(timer, 1000);
function timer() {
timeCount.textContent = time; time--;
timeCount.textContent = time;
time--;
if (time < 9) {
let addZero = timeCount.textContent;
timeCount.textContent = "0" + addZero;
Expand Down Expand Up @@ -183,6 +192,7 @@ incrementScore = (num) => {
score += num;
scoreText.innerText = score;
};

var count=0;
function muteMe(elem) {
elem.muted = true;
Expand Down
20 changes: 15 additions & 5 deletions Light/game.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ const time_line = document.querySelector(".time .time_line");
const timeText = document.querySelector(".timer .time_left_txt");
const timeCount = document.querySelector(".timer .timer_sec");


var soundCorrect = new Audio("sounds/correctAns.mp3");
var soundIncorrect = new Audio("sounds/wrongAns.mp3");
var myMusic = new Audio("sounds/gametheme.mp3");
Expand All @@ -26,7 +25,6 @@ let widthValue = 0;

let questions = [];


fetch(
'https://opentdb.com/api.php?amount=10&category=17&difficulty=easy&type=multiple'
)
Expand Down Expand Up @@ -60,7 +58,7 @@ fetch(
console.error(err);
});

//CONSTANTS
// CONSTANTS
const CORRECT_BONUS = 10;
const MAX_QUESTIONS = 10;

Expand Down Expand Up @@ -124,8 +122,18 @@ choices.forEach((choice) => {
clearInterval(counter);
clearInterval(counterLine);

const timeRemaining = parseInt(timeCount.textContent);

if (classToApply === 'correct') {
incrementScore(CORRECT_BONUS);
let scoreToAdd = 0;
if (timeRemaining > 10 && timeRemaining <= 15) {
scoreToAdd = 10;
} else if (timeRemaining > 5 && timeRemaining <= 10) {
scoreToAdd = 5;
} else if (timeRemaining > 0 && timeRemaining <= 5) {
scoreToAdd = 2;
}
incrementScore(scoreToAdd);
soundCorrect.play();
} else {
soundIncorrect.play();
Expand All @@ -143,7 +151,8 @@ choices.forEach((choice) => {
function startTimer(time) {
counter = setInterval(timer, 1000);
function timer() {
timeCount.textContent = time; time--;
timeCount.textContent = time;
time--;
if (time < 9) {
let addZero = timeCount.textContent;
timeCount.textContent = "0" + addZero;
Expand Down Expand Up @@ -183,6 +192,7 @@ incrementScore = (num) => {
score += num;
scoreText.innerText = score;
};

var count=0;
function muteMe(elem) {
elem.muted = true;
Expand Down

0 comments on commit e63e609

Please sign in to comment.