Skip to content

Commit

Permalink
Auto commit by script on 2024-01-02 12:37:23
Browse files Browse the repository at this point in the history
  • Loading branch information
linusbierhoff committed Jan 2, 2024
1 parent e4f1b44 commit c56964f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ <h3>The dot in the middle indicates that your phone is centered.</h3>
<h2>Press start to begin!</h2>
<button class="rounded-button" id="start-button">Start</button>
</div>
<script src="script/global.js"></script>
<script src="lib/modernizr-custom.js"></script>
<script src="script/models/category.js"></script>
<script src="script/start.js"></script>
Expand Down
15 changes: 12 additions & 3 deletions script/global.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
const stopWatch = new Stopwatch();
let correct_answers = 0;
let category = 9; //init
const SECONDS = "seconds";
const CORRECT_ANSWERS = "correct_answers"
const CATEGORY = "category";

function saveState(key, value) {
localStorage.setItem(key, JSON.stringify(value));
}

function getState(key) {
const savedState = localStorage.getItem(key);
return savedState ? JSON.parse(savedState) : null;
}
6 changes: 6 additions & 0 deletions script/question.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ const stopwatch_text = document.getElementById("stopwatch");

let current_question = null;
let questions;
let correct_answers;
let stopWatch = new Stopwatch();
let category = getState(CATEGORY);


activateFullscreenOverlay(`<h3>Loading questions...</h3>`)
console.log(`https://opentdb.com/api.php?amount=10&type=multiple&category=${category}`);
Expand Down Expand Up @@ -32,6 +36,8 @@ function setQuestion() {
if (length === 0) {
done = true;
stopWatch.stop();
saveState(SECONDS, stopWatch.seconds);
saveState(CORRECT_ANSWERS, correct_answers);
window.location.href = "result.html";
return;
}
Expand Down
3 changes: 1 addition & 2 deletions script/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ if (Modernizr.deviceorientation) {
loadCategories().then(r => {

category_menu.addEventListener("change", (event) => {
category = category_menu.value;
console.log(category);
saveState(CATEGORY, category_menu.value);
})
document.getElementById('start-button').addEventListener('click', onStart);
});
Expand Down

0 comments on commit c56964f

Please sign in to comment.