Skip to content
Draft
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
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ <h3 id="progress">Progress: 0% (0/0 tasks completed)</h3>
<h2 id="time">00:00:00</h2>
<button onclick="startTimer()">Start</button>
<button onclick="stopTimer()">Stop</button>
<button onclick="Restart()"> Restart</button>
</div>
</div>

Expand Down
23 changes: 23 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,27 @@ function updateTime() {

function pad(num) {
return num < 10 ? "0" + num : num;
}
//stop timer when task is completed
function stop() {
let total = tasks.length;
if (total === 0) return;
let doneTasks = tasks.filter(task => task.done).length;
let percent = Math.round((doneTasks / total) * 100);

if (percent === 100) {
stopTimer();
}
}
function toggleTask(index) {
tasks[index].done = !tasks[index].done;
renderTasks();
stop();
}
// Restart
function Restart(){
seconds=0;
updateTime();
tasks = [];
renderTasks();
}