-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathscript.js
More file actions
137 lines (133 loc) · 4.12 KB
/
Copy pathscript.js
File metadata and controls
137 lines (133 loc) · 4.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
const tasks = [
{
startedAt: new Date("2021-01-19:12:45"),
finishedAt: new Date("2021-01-20:19:45"),
tasksGiven: 20,
tasksFinished: 10,
topic: "HTML"
},
{
startedAt: new Date("2021-01-20:09:30"),
finishedAt: new Date("2021-01-20:11:15"),
tasksGiven: 30,
tasksFinished: 10,
topic: "JavaScript"
},
{
startedAt: new Date("2021-01-20:12:15"),
finishedAt: new Date("2021-01-20:15:00"),
tasksGiven: 13,
tasksFinished: 8,
topic: "Arrays"
},
{
startedAt: new Date("2021-01-20:11:30"),
finishedAt: new Date("2021-01-20:14:30"),
tasksGiven: 5,
tasksFinished: 1,
topic: "Conditions"
},
{
startedAt: new Date("2021-01-20:08:30"),
finishedAt: new Date("2021-01-20:15:15"),
tasksGiven: 2,
tasksFinished: 2,
topic: "Loops"
},
{
startedAt: new Date("2021-01-20:09:00"),
finishedAt: new Date("2021-01-20:14:00"),
tasksGiven: 12,
tasksFinished: 7,
topic: "GitHub"
},
{
startedAt: new Date("2021-01-20:12:00"),
finishedAt: new Date("2021-01-20:13:30"),
tasksGiven: 16,
tasksFinished: 10,
topic: "CSS"
},
{
startedAt: new Date("2021-01-20:10:00"),
finishedAt: new Date("2021-01-20:11:00"),
tasksGiven: 4,
tasksFinished: 3,
topic: "DOM Manipulations"
},
{
startedAt: new Date("2021-01-20:09:30"),
finishedAt: new Date("2021-01-20:12:00"),
tasksGiven: 1,
tasksFinished: 1,
topic: "JSON"
},
{
startedAt: new Date("2021-01-20:13:00"),
finishedAt: new Date("2021-01-20:18:00"),
tasksGiven: 6,
tasksFinished: 4,
topic: "Functions"
}
]
document.write('<h1>Tasks To-Do:</h1>');
document.write('<div><table style="width:80%">');
document.write(`<tr> <th>Topic</th> <th>start</th> <th>finished</th> <th>time on</th> <th>tasks given</th> <th>tasks finished</th> <th>Done %</th></tr>`)
for(task of tasks){
const padZeroStart=padZero((task.startedAt.getMinutes()/60));
const padZeroEnd=padZero((task.finishedAt.getMinutes()/60));
//------------ find the time spent on each task --------------------//
let start = task.startedAt.getHours()+ (task.startedAt.getMinutes()/60);
let end = task.finishedAt.getHours()+ (task.finishedAt.getMinutes()/60);
task.timeTotal= end - start;
//------------ set the hours of start & finish ---------------------//
let startTime="", endTime="";
startTime= task.startedAt.getHours()+":"+ task.startedAt.getMinutes();
endTime= task.finishedAt.getHours()+":"+ task.finishedAt.getMinutes();
//------------ finding the percentage of tasks finished ------------//
donePercentage= Math.floor((task.tasksFinished/task.tasksGiven)*100);
task.tasksFinishedPercentage= donePercentage+ "%";
//------------ creating the table contents -------------------------//
document.write(`<tr><td>${task.topic}</td>
<td>${startTime}${padZeroStart}</td>
<td>${endTime}${padZeroEnd}</td>
<td class=${checkTimeOnTask(task.timeTotal)}>${task.timeTotal}</td>
<td>${task.tasksGiven}</td>
<td>${task.tasksFinished}</td>
<td class=${findPercentage(donePercentage)}>${task.tasksFinishedPercentage}</td>
</tr>`);
}
document.write('</table></י>');//closing the table
//-------- functions -----------//
//-------- changing background by percentage ---------------------------//
function findPercentage(num){
if(num>=75){
return "Aclass";
}
else if(num<50){
return "underFifty";
}
else{
return "Bclass";
}
}
//-------- padding zero to the minutes if tey are zero (i.e. 14:*00*)---//
function padZero(num){
if(num===0){
return "0";
}
return "";
}
//-------- changing background color based on hours on task ------------//
function checkTimeOnTask(num){
console.log(num);
if(num<2.5){
return "low";
}
else if(num< 4.5){
return "justRight";
}
else{
return "high";
}
}