Skip to content

Commit

Permalink
version two
Browse files Browse the repository at this point in the history
  • Loading branch information
farahmahfouz committed Jul 14, 2024
1 parent 2812402 commit 3bd0e3b
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 22 deletions.
11 changes: 11 additions & 0 deletions js/User.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export class User {
constructor(f, l, e, p) {
this.firstName = f;
this.lastName = l;
this.email = e;
this.password = p;
}
}



29 changes: 19 additions & 10 deletions js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ let timerDisplay = document.getElementById("timeLeft");
let markedQuestionsDiv = document.getElementById("markedQuestions");
let timerInterval;
let currentIndex = 0;
let timeLeft = 400; // Total time in seconds
let timeLeft = 10; // Total time in seconds

function updateQuestion() {
let currentQuestion = quiz[currentIndex];
impo.textContent = currentQuestion.title;

for (let i = 0; i < options.length; i++) {
options[i].querySelector("label").textContent = currentQuestion.answers[i].body;
radioInputs[i].checked = false; // Reset radio button selection
radioInputs[i].disabled = false; // Enable radio buttons
// radioInputs[i].disabled = false; // Enable radio buttons

// Highlight selected answer if already selected
if (currentQuestion.getSelectedAnswer() === i) {
Expand Down Expand Up @@ -82,15 +83,19 @@ function calculateScore() {
return correctAnswers;
}



function startTimer(minutes) {
let seconds = minutes * 60;

function updateCountdown() {
let mins = Math.floor(seconds / 60);
let secs = seconds % 60;

secs = secs < 10 ? '0' + secs : secs; // add leading zero if seconds less than 10
timerDisplay.textContent = `${mins}:${secs}`;


if (seconds > 0) {
seconds--;
setTimeout(updateCountdown, 1000);
Expand All @@ -112,7 +117,7 @@ function toggleMarkQuestion() {
let currentQuestion = quiz[currentIndex];

// Check if the question is already marked
let existingMarkedQuestion = Array.from(markedQuestionsDiv.children).find((div) => parseInt(div.dataset.index) === currentIndex);
let existingMarkedQuestion = Array.from(markedQuestionsDiv.children).find((div) => Number(div.dataset.index) === currentIndex);

if (!existingMarkedQuestion) {
// Mark the question
Expand All @@ -137,7 +142,7 @@ function toggleMarkQuestion() {
}

function updateMarkButton() {
let currentQuestion = quiz[currentIndex];
// let currentQuestion = quiz[currentIndex];
let existingMarkedQuestion = Array.from(markedQuestionsDiv.children).find((div) => parseInt(div.dataset.index) === currentIndex);

if (existingMarkedQuestion) {
Expand All @@ -162,6 +167,16 @@ function toggleMarkedQuestionsSection() {
}
}


function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}



shuffleArray(quiz);
updateQuestion();
startTimer(timeLeft); // Start the timer when the page loads
Expand Down Expand Up @@ -196,9 +211,3 @@ radioInputs.forEach((radio, index) => {
});
});

function shuffleArray(array) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
}
11 changes: 1 addition & 10 deletions js/register.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getUsersArr } from "./helper.js";
import { User } from "./User.js";

let form = document.getElementsByClassName("form")[0];
console.log(form)
Expand Down Expand Up @@ -101,13 +102,3 @@ function validation(event) {

form.addEventListener("submit", validation);

class User {
constructor(f, l, e, p) {
this.firstName = f;
this.lastName = l;
this.email = e;
this.password = p;
}
}


2 changes: 1 addition & 1 deletion quiz.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</head>
<body>
<div class="container">
<div id="timer">Time out:<span id="timeLeft"></span></div>
<div id="timer"><span id="timeLeft"></span></div>
<div class="question-seqtion">
<div class="test">
<div class="question-collector">
Expand Down
2 changes: 1 addition & 1 deletion register.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ <h2>Sign Up</h2>
</div>
<div class="form-group">
<div class="form-input">
<label for="reEnterPassword">Re-enter Password</label>
<label for="reEnterPassword">Re-Password</label>
<input type="password" id="reEnterPassword" name="reEnterPassword" placeholder="password" />
<span id="span-reEnter"></span>
</div>
Expand Down

0 comments on commit 3bd0e3b

Please sign in to comment.