Skip to content
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
Binary file added public/timer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/components/Button.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ button:hover {
position: relative;
}

img {
.wrapper img {
width: 70px;
height: 70px;
transform: translateY(-10px);
Expand All @@ -33,6 +33,6 @@ img {
position: absolute;
}

.hidden {
.wrapper .hidden {
opacity: 0;
}
14 changes: 14 additions & 0 deletions src/components/timer/quiz-timer.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#clock {
color: white;
font-size: 50px;
display: flex;
justify-content: center;
align-items: center;
gap: 5px;
}

#clock img {
height: 70px;
width: auto;
margin: 10px;
}
58 changes: 58 additions & 0 deletions src/components/timer/quiz-timer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
let timer;

export function createTimer() {
const clock = document.createElement('div');
clock.setAttribute('id', 'clock');

const image = document.createElement('img');
image.src = '/timer.png';

const minutes = document.createElement('span');
minutes.setAttribute('id', 'timer-minutes');

const colon = document.createElement('span');
colon.innerText = ':';

const seconds = document.createElement('span');
seconds.setAttribute('id', 'timer-seconds');

clock.appendChild(image);
clock.appendChild(minutes);
clock.appendChild(colon);
clock.appendChild(seconds);

return clock;
}

export function startTimer() {
let minutes = 0;
let seconds = 0;
const min = document.getElementById('timer-minutes');
const sec = document.getElementById('timer-seconds');

min.innerText = '00';
sec.innerText = '00';
Comment on lines +33 to +34
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is duplicated in createTimer function;

Keep it just here


timer = setInterval(function () {
seconds++;
if (seconds === 60) {
seconds = 0;
minutes++;
if (minutes === 60) {
minutes = 0;
}
min.innerText = timerDigits(minutes);
}
sec.innerText = timerDigits(seconds);
}, 1000);
}

export function stopTimer() {
const clk = document.getElementById('clock');
clk.style.display = 'none';
clearInterval(timer);
}

function timerDigits(time_value) {
return time_value < 10 ? '0' + time_value : time_value;
}
6 changes: 6 additions & 0 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import './style.css';
import './components/timer/quiz-timer.css';
import { createTimer, startTimer, stopTimer } from './components/timer/quiz-timer.js';
import Button from './components/Button.js';

document.querySelector('#app').innerHTML = `
Expand All @@ -18,3 +20,7 @@ const buttonStatic = Button('abort koala', 'noKoala', false, 'click', simpleCall

document.querySelector('#app').append(buttonQuiz, buttonLeaderboard, buttonAdoption, buttonCredits);
document.querySelector('#app').append(buttonStatic);


document.querySelector('#app').appendChild(createTimer());
startTimer();
4 changes: 4 additions & 0 deletions src/style.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
body {
background-color: #8ab0ab;
}

#app {
font-family: Avenir, Helvetica, Arial, sans-serif;
-webkit-font-smoothing: antialiased;
Expand Down