Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redo Quiz UI #36

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 83 additions & 2 deletions public/css/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,52 @@ nav ul li a.active::after {
display: block;
}

/* Container for previous and next buttons */
.navigation-buttons {
display: flex;
justify-content: center;
align-items: center;
gap: 10px;
}

#prevButton,
#nextButton {
padding: 10px 20px;
font-size: 16px;
cursor: pointer;
border: none;
border-radius: 5px;
margin-top: 20px;
display: inline-block;
margin-right: 10px;
}

#prevButton {
background-color: #4CAF50;
color: white;
}

#nextButton {
background-color: #2196F3;
color: white;
}

#backToLastQuestion {
background-color: #4CAF50;
color: white;
margin-top: 20px;
display: block;
}

#submitButton {
margin-bottom: 10px;
}

#prevButton:hover,
#nextButton:hover {
opacity: 0.8;
}

/* Quiz Section */
.quiz {
background-color: var(--secondary-color);
Expand All @@ -267,17 +313,47 @@ nav ul li a.active::after {
gap: 2rem;
}

.quiz-card {
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 10px;
padding: 20px;
margin-bottom: 20px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

.quiz-card .quiz-question {
font-size: 1.2em;
margin-bottom: 15px;
color: #333;
}

.quiz-card .quiz-options label {
display: block;
margin: 10px 0;
font-size: 1em;
color: #555;
}

.quiz-card .quiz-options input {
margin-right: 10px;
}

.quiz-card .quiz-options label:hover {
background-color: #f0f0f0;
}

.quiz-info {
max-width: 60%;
flex: 1;
}

.quiz-img {
/* .quiz-img {
max-width: 40%;
border-radius: 10px;
box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
flex: 1;
}
} */

@media (max-width: 768px) {
.quiz-content {
Expand All @@ -295,6 +371,11 @@ nav ul li a.active::after {
}
}

/* #quizProgress {
height: 10px;
border-radius: 5px;
} */

/* Quiz Results Section */
.results-container {
margin: 2rem auto;
Expand Down
115 changes: 114 additions & 1 deletion public/js/quiz.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,132 @@
document.addEventListener('DOMContentLoaded', () => {
const toggleQuizBtn = document.getElementById('toggle-quiz');
const quizForm = document.getElementById('learning-type-quiz');
const nextButton = document.getElementById('nextButton');
const prevButton = document.getElementById('prevButton');

let isFirstClick = true;
let isRestart = false;

toggleQuizBtn.onclick = function () {
if (isRestart) {
quizForm.reset();
document.getElementById('quiz-results').style.display = 'none';
document.getElementById("backToLastQuestion").style.display = "none";
isFirstClick = true;
isRestart = false;
}

if (quizForm.style.display === 'none') {
quizForm.style.display = 'block';
toggleQuizBtn.innerText = 'Hide Quiz';

let resultsContainer = document.getElementById('quiz-results');
if (resultsContainer.style.display != 'none') {
quizForm.reset();
resultsContainer.style.display = 'none';
}

if (isFirstClick) {
document.getElementById(`question1`).style.display = "block";
isFirstClick = false;
isRestart = false;
} else {
document.getElementById("prevButton").style.display = "block";
}

document.getElementById("nextButton").style.display = "block";

} else {
quizForm.style.display = 'none';
toggleQuizBtn.innerText = 'Start Quiz';
document.getElementById("nextButton").style.display = 'none';
document.getElementById("prevButton").style.display = 'none';
}
};

let currentQuestionIndex = 1;

nextButton.onclick = function () {
const currentQuestion = document.getElementById(`question${currentQuestionIndex}`);

const questionName = `q${currentQuestionIndex}`;
const selectedAnswer = document.querySelector(
`input[name="${questionName}"]:checked`
);

if (!selectedAnswer) {
alert('Please select an option!');
} else {
currentQuestion.style.display = "none";

currentQuestionIndex++;

const nextQuestion = document.getElementById(`question${currentQuestionIndex}`);

if (nextQuestion == null) {
document.getElementById('toggle-quiz').style.display = "none";
document.getElementById("nextButton").style.display = "none";
document.getElementById("prevButton").style.display = "none";
document.getElementById("submitButton").style.display = "block";
document.getElementById("backToLastQuestion").style.display = "block";
} else {
nextQuestion.style.display = "block";
prevButton.style.display = "block";
}

document.getElementById("quizProgress").value = currentQuestionIndex;
}

};

prevButton.onclick = function () {
const currentQuestion = document.getElementById(`question${currentQuestionIndex}`);
currentQuestion.style.display = "none";

currentQuestionIndex--;

const prevQuestion = document.getElementById(`question${currentQuestionIndex}`);

if (currentQuestionIndex == 1) {
prevButton.style.display = "none";
document.getElementById(`question1`).style.display = "block";
isFirstClick = true;
} else {
document.getElementById(`question1`).style.display = "none";
prevQuestion.style.display = "block";
}

document.getElementById("quizProgress").value = currentQuestionIndex;

};

document.getElementById("submitButton").onclick = function () {
document.getElementById("submitButton").style.display = "none";

document.getElementById('toggle-quiz').style.display = "block";
document.getElementById('toggle-quiz').innerText = "Restart Quiz";
isRestart = true;
currentQuestionIndex = 1;

document.getElementById("quizProgress").value = 0;

document.getElementById("nextButton").style.display = "none";
document.getElementById("prevButton").style.display = "none";
document.getElementById("backToLastQuestion").style.display = "none";
};

document.getElementById("backToLastQuestion").onclick = function () {
document.getElementById("submitButton").style.display = "none";
document.getElementById("backToLastQuestion").style.display = "none";

currentQuestionIndex--;
const currentQuestion = document.getElementById(`question${currentQuestionIndex}`);
currentQuestion.style.display = "block";

document.getElementById("nextButton").style.display = "block";
document.getElementById("prevButton").style.display = "block";

document.getElementById("quizProgress").value = currentQuestionIndex;
};

const answerWeights = {
Expand Down Expand Up @@ -152,7 +265,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (dominantStyleInfo.title === 'Visual Learner') {
dominantColor = '#3498db';
} else if (dominantStyleInfo.title == 'Auditory Learner') {
dominantColor = 'e74c3c';
dominantColor = '#e74c3c';
} else if (dominantStyleInfo.title == 'Kinesthetic Learner') {
dominantColor = '#2ecc71';
} else {
Expand Down
Loading
Loading