@@ -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
2102541. Add routing for the `about` page
0 commit comments