Skip to content

Commit d6f2de0

Browse files
committed
modified: public/README.md
modified: views/pages/utils.ejs
1 parent 7a58972 commit d6f2de0

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
lines changed

public/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,50 @@ Partial files are pieces of reusable code segment that typically appear again an
205205
</html>
206206
```
207207

208+
7. Create ejs file `utils.ejs` containing client-side functions. Notice the ejs tags <% ... %>
209+
210+
```c
211+
<%
212+
213+
// Convert Unix_TimeStamp to Local DateTime.
214+
unixTsToLocalTime = (unix_ts) => {
215+
// Create a new JavaScript Date object based on the timestamp
216+
// multiplied by 1000 so that the argument is in milliseconds, not seconds.
217+
var date = new Date(unix_ts * 1000);
218+
// Hours part from the timestamp
219+
var hours = date.getHours();
220+
// Minutes part from the timestamp
221+
var minutes = "0" + date.getMinutes();
222+
// Seconds part from the timestamp
223+
var seconds = "0" + date.getSeconds();
224+
225+
// Will display time in 10:30:23 format
226+
return hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
227+
}
228+
229+
// Return verbish base on temperature trending.
230+
trendingTemperature = (dataArr) => {
231+
var sum = 0;
232+
for (var item of dataArr) {
233+
sum += item.temp;
234+
}
235+
let average = sum / dataArr.length;
236+
let diff = average - dataArr[0].temp;
237+
if ( diff > 0 ) {
238+
if (diff <= 3){ return "Slight warming trend ahead."; }
239+
else if (diff > 3 && diff <= 10) { return "Moderate warming trend ahead."; }
240+
else { return "Considerable warming trend ahead."; }
241+
} else {
242+
if (diff >= -3){ return "Slight cooling trend ahead."; }
243+
else if (diff < -3 && diff <= -10) { return "Moderate cooling trend ahead."; }
244+
else { return "Considerable warming trend ahead."; }
245+
}
246+
}
247+
%>
248+
```
249+
250+
<br />
251+
208252
<strong>Implement server-side routings </strong>
209253
210254
1. Add routing for the `about` page

views/pages/utils.ejs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,13 @@ trendingTemperature = (dataArr) => {
2323
let average = sum / dataArr.length;
2424
let diff = average - dataArr[0].temp;
2525
if ( diff > 0 ) {
26-
return "Warming trend ahead.";
26+
if (diff <= 3){ return "Slight warming trend ahead."; }
27+
else if (diff > 3 && diff <= 10) { return "Moderate warming trend ahead."; }
28+
else { return "Considerable warming trend ahead."; }
2729
} else {
28-
return "Cooling trend ahead.";
30+
if (diff >= -3){ return "Slight cooling trend ahead."; }
31+
else if (diff < -3 && diff <= -10) { return "Moderate cooling trend ahead."; }
32+
else { return "Considerable warming trend ahead."; }
2933
}
3034
}
3135
%>

0 commit comments

Comments
 (0)