Skip to content
Open
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
12 changes: 11 additions & 1 deletion QuizApp/ANKUR2304/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">

<!-- Fontawesome CSS CDN -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/css/all.min.css"/>
<link href="styles.css" rel="stylesheet">
<script defer src="script.js"></script>
<title>Quiz Game</title>
</head>
<body>
<!-- Theme button -->
<div class="theme-button">
<button id="light-theme-btn"><i class="fas fa-sun fa-2x"></i></button>
<button id="dark-theme-btn"><i class="fas fa-moon fa-2x"></i></button>
</div>

<div class="container">
<div id="question-container" class="hide">
<div id="question">Question</div>
Expand All @@ -27,5 +34,8 @@
</div>

</div>

<!-- Fontawesome JS CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/7.0.1/js/all.min.js"></script>
</body>
</html>
44 changes: 44 additions & 0 deletions QuizApp/ANKUR2304/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ const questionContainerElement = document.getElementById("question-container");
const questionElement = document.getElementById("question");
const answerButtonsElement = document.getElementById("answer-buttons");

// Theme buttons
const lightThemeButton = document.getElementById('light-theme-btn');
const darkThemeButton = document.getElementById('dark-theme-btn');
// Theme body
const mainContainer = document.querySelector('.container');


let shuffledQuestions, currentQuestionIndex;

startButton.addEventListener("click", startGame);
Expand Down Expand Up @@ -123,3 +130,40 @@ const questions = [
],
},
];


// Check for saved theme preference on page load
window.addEventListener('load', () => {
const savedDarkMode = localStorage.getItem('darkMode');
if (savedDarkMode === 'enabled') {
applyDarkTheme();
} else {
applyLightTheme();
}
});

// Dark theme activation
darkThemeButton.addEventListener('click', () => {
applyDarkTheme();
localStorage.setItem('darkMode', 'enabled');
});

// Dark theme deactivation
lightThemeButton.addEventListener('click', () => {
applyLightTheme();
localStorage.setItem('darkMode', 'disabled');
});

// Function to apply dark theme styles
function applyDarkTheme() {
darkThemeButton.style.display = 'none';
lightThemeButton.style.display = 'initial';
mainContainer.classList.add('container-dark');
}

// Function to apply light theme styles
function applyLightTheme() {
darkThemeButton.style.display = 'initial';
lightThemeButton.style.display = 'none';
mainContainer.classList.remove('container-dark');
}
29 changes: 29 additions & 0 deletions QuizApp/ANKUR2304/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,33 @@

.hide {
display: none;
}

/*--==================================
Dark theme styles
==================================--*/
.theme-button {
width: 100%;
padding: 30px;
text-align: right;
position: fixed;
top: 0;
}

.theme-button button {
background: transparent;
border: none;
color: #ffffff;
cursor: pointer;
padding: 5px;
}

.theme-button #light-theme-btn {
display: none;
}

.container-dark {
background: #000000;
color: #ffffff;
box-shadow: 0 0 10px 2px #000000;
}