File tree 3 files changed +40
-57
lines changed
3 files changed +40
-57
lines changed Original file line number Diff line number Diff line change 1
1
<!DOCTYPE html>
2
- < html >
3
- < head >
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge ">
6
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
4
7
< title > Pomodoro Timer</ title >
5
- < link rel ="stylesheet " type =" text/css " href ="style.css " / >
6
- </ head >
7
- < body >
8
+ < link rel ="stylesheet " href ="style.css ">
9
+ </ head >
10
+ < body >
8
11
< div class ="container ">
9
- < h1 class ="title "> Pomodoro Timer</ h1 >
10
- < p id ="timer " class ="timer "> 25:00</ p >
11
- < div class ="button-wrapper ">
12
- < button id ="start " class =" button button-- start "> Start</ button >
13
- < button id ="stop " class =" button button-- stop "> Stop</ button >
14
- < button id ="reset " class =" button button-- reset "> Reset</ button >
15
- </ div >
12
+ < h1 class ="title "> Pomodoro Timer</ h1 >
13
+ < p class ="timer " id ="timer "> 25:00</ p >
14
+ < div class ="button-wrapper ">
15
+ < button id ="start "> Start</ button >
16
+ < button id ="stop "> Stop</ button >
17
+ < button id ="reset "> Reset</ button >
18
+ </ div >
16
19
</ div >
17
20
< script src ="index.js "> </ script >
18
- </ body >
19
- </ html >
21
+ </ body >
22
+ </ html >
Original file line number Diff line number Diff line change @@ -3,41 +3,36 @@ const stopEl = document.getElementById("stop");
3
3
const resetEl = document . getElementById ( "reset" ) ;
4
4
const timerEl = document . getElementById ( "timer" ) ;
5
5
6
- let intervalId ;
7
- let timeLeft = 1500 ; // 25 minutes in seconds
6
+ let interval ;
7
+ let timeLeft = 1500 ;
8
8
9
9
function updateTimer ( ) {
10
10
let minutes = Math . floor ( timeLeft / 60 ) ;
11
11
let seconds = timeLeft % 60 ;
12
12
let formattedTime = `${ minutes . toString ( ) . padStart ( 2 , "0" ) } :${ seconds
13
13
. toString ( )
14
14
. padStart ( 2 , "0" ) } `;
15
- // padStart() is a built-in method in JavaScript that allows you to pad a string with another string until it reaches a specified length. It's often used to format strings to a specific length, such as adding leading zeros to a number.
16
- // const str = '7';
17
- // const paddedStr = str.padStart(2, '0');
18
-
19
- // console.log(paddedStr); // Output: '07'
20
15
21
16
timerEl . innerHTML = formattedTime ;
22
17
}
23
18
24
19
function startTimer ( ) {
25
- intervalId = setInterval ( ( ) => {
20
+ interval = setInterval ( ( ) => {
26
21
timeLeft -- ;
27
22
updateTimer ( ) ;
28
23
if ( timeLeft === 0 ) {
29
- clearInterval ( intervalId ) ;
24
+ clearInterval ( interval ) ;
30
25
alert ( "Time's up!" ) ;
26
+ timeLeft = 1500 ;
27
+ updateTimer ( ) ;
31
28
}
32
29
} , 1000 ) ;
33
30
}
34
-
35
31
function stopTimer ( ) {
36
- clearInterval ( intervalId ) ;
32
+ clearInterval ( interval ) ;
37
33
}
38
-
39
34
function resetTimer ( ) {
40
- clearInterval ( intervalId ) ;
35
+ clearInterval ( interval ) ;
41
36
timeLeft = 1500 ;
42
37
updateTimer ( ) ;
43
38
}
Original file line number Diff line number Diff line change 1
- /* Pomodoro Timer styles */
2
-
3
1
.container {
4
- font-family : "Roboto" , Arial, Helvetica, sans-serif;
5
2
margin : 0 auto;
6
3
max-width : 400px ;
7
- padding : 20px ;
8
4
text-align : center;
5
+ padding : 20px ;
6
+ font-family : "Roboto" , sans-serif;
9
7
}
10
8
11
9
.title {
19
17
color : # 2c3e50 ;
20
18
}
21
19
22
- .button-wrapper {
23
- display : flex;
24
- justify-content : center;
25
- }
20
+ button {
21
+ font-size : 18px ;
22
+ padding : 10px 20px ;
23
+ margin : 10px ;
24
+ color : white;
26
25
27
- .button {
28
26
border : none;
29
27
border-radius : 4px ;
30
- color : # fff ;
31
- font-size : 18px ;
32
- font-weight : bold;
33
- margin-right : 10px ;
34
- padding : 10px 20px ;
35
- text-transform : uppercase;
36
- transition : all 0.2s ;
37
28
cursor : pointer;
29
+ text-transform : uppercase;
30
+ transition : opacity 0.3s ease-in-out;
38
31
}
39
32
40
- . button--start {
41
- background-color : # 27ae60 ;
33
+ button : hover {
34
+ opacity : 0.7 ;
42
35
}
43
36
44
- . button-- start: hover {
45
- background-color : # 229954 ;
37
+ # start {
38
+ background-color : # 27ae60 ;
46
39
}
47
40
48
- . button-- stop {
41
+ # stop {
49
42
background-color : # c0392b ;
50
43
}
51
44
52
- .button--stop : hover {
53
- background-color : # a93226 ;
54
- }
55
-
56
- .button--reset {
45
+ # reset {
57
46
background-color : # 7f8c8d ;
58
47
}
59
-
60
- .button--reset : hover {
61
- background-color : # 6c7a7d ;
62
- }
You can’t perform that action at this time.
0 commit comments