Skip to content

Commit 1fc1de0

Browse files
Add files via upload
1 parent 14959a2 commit 1fc1de0

File tree

3 files changed

+129
-0
lines changed

3 files changed

+129
-0
lines changed

timer/assets/js/index.js

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
function main () {
2+
const timer = document.querySelector('.timer');
3+
const startButton = document.querySelector('.start');
4+
const stopButton = document.querySelector('.stop');
5+
const restartButton = document.querySelector('.restart');
6+
let timerJS = [0, 0, 0];
7+
let timerJSString;
8+
9+
function timerFunction (list) {
10+
if (list[2] < 59) {
11+
list[2]++
12+
return list
13+
} else if (list[1] < 59) {
14+
list[1]++
15+
return list
16+
} else if (list[0] < 23) {
17+
list[0]++
18+
return list
19+
} else {
20+
return list
21+
}
22+
}
23+
24+
25+
function convertString (list) {
26+
list = [`${list[0]}`, `${list[1]}`, `${list[2]}`]
27+
if (list[2] < 10) {
28+
list[2] = `0${list[2]}`
29+
}
30+
if (list[1] < 10) {
31+
list[1] = `0${list[1]}`
32+
}
33+
if (list[0] < 10) {
34+
list[0] = `0${list[0]}`
35+
}
36+
return list
37+
}
38+
39+
40+
startButton.addEventListener('click', function startFunction () {
41+
const time = setInterval(function time () {
42+
timer.classList.remove('paused')
43+
timerJSString = convertString(timerFunction(timerJS))
44+
timer.innerHTML = `${timerJSString[0]}:${timerJSString[1]}:${timerJSString[2]}`
45+
}, 900);
46+
stopButton.addEventListener('click', function () {
47+
setTimeout(function () {
48+
clearInterval(time)
49+
}, 10);
50+
timer.classList.add('paused')
51+
})
52+
return
53+
});
54+
restartButton.addEventListener('click', function () {
55+
timerJS = [0, 0, 0];
56+
timerJSString = ['00', '00', '00']
57+
timer.innerHTML = `${timerJSString[0]}:${timerJSString[1]}:${timerJSString[2]}`
58+
timer.classList.remove('paused')
59+
})
60+
}
61+
62+
63+
main()

timer/assets/styles/styles.css

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
* {
2+
margin: 0;
3+
padding: 0;
4+
}
5+
:root {
6+
--background-color-one: rgb(2, 120, 112);
7+
--background-color-two: rgb(206, 255, 252);
8+
}
9+
.container {
10+
background-color: var(--background-color-one);
11+
width: 100%;
12+
height: 100vh;
13+
display: flex;
14+
justify-content: center;
15+
align-items: flex-start;
16+
}
17+
.introduction {
18+
width: 60vw;
19+
height: auto;
20+
margin-top: 10vh;
21+
background-color: var(--background-color-two);
22+
padding: 2vmin;
23+
border: solid var(--background-color-two);
24+
border-radius: 10px;
25+
font-size: 1.2em;
26+
display: flex;
27+
gap: 2vmin;
28+
flex-direction: column;
29+
}
30+
.timer {
31+
font-size: 2em;
32+
}
33+
.introduction button {
34+
padding: 1vmin;
35+
width: 8vmin;
36+
margin: 1vh 0 0 0;
37+
}
38+
.paused {
39+
color: red;
40+
}

timer/index.html

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Document</title>
8+
<link rel="stylesheet" href="./assets/styles/styles.css">
9+
</head>
10+
11+
<body>
12+
<section class="container">
13+
<div class="introduction">
14+
<h1>Meu Timer</h1>
15+
<div>
16+
<h2 class="timer">00:00:00</h2>
17+
<button class="start">start</button>
18+
<button class="stop">stop</button>
19+
<button class="restart">restart</button>
20+
</div>
21+
</div>
22+
</section>
23+
<script src="./assets/js/index.js"></script>
24+
</body>
25+
26+
</html>

0 commit comments

Comments
 (0)