@@ -179,14 +179,59 @@ Partial files are pieces of reusable code segment that typically appear again an
179179 </html>
180180```
181181
182- 6 . Create ejs template file ` index.ejs ` , and inject partial files as follow.
182+
183+ 6 . Create ejs file ` utils.ejs ` containing client-side functions. Notice the ejs tags <% ... %>
184+
185+ ``` c
186+ <%
187+
188+ // Convert Unix_TimeStamp to Local DateTime.
189+ unixTsToLocalTime = (unix_ts) => {
190+ // Create a new JavaScript Date object based on the timestamp
191+ // multiplied by 1000 so that the argument is in milliseconds, not seconds.
192+ var date = new Date(unix_ts * 1000);
193+ // Hours part from the timestamp
194+ var hours = date.getHours();
195+ // Minutes part from the timestamp
196+ var minutes = "0" + date.getMinutes();
197+ // Seconds part from the timestamp
198+ var seconds = "0" + date.getSeconds();
199+
200+ // Will display time in 10:30:23 format
201+ return hours + ':' + minutes.substr(-2) + ':' + seconds.substr(-2);
202+ }
203+
204+ // Return verbish based on temperature trending.
205+ trendingTemperature = (dataArr) => {
206+ var sum = 0;
207+ for (var item of dataArr) {
208+ sum += item.temp;
209+ }
210+ let average = sum / dataArr.length;
211+ let diff = average - dataArr[0].temp;
212+ if ( diff > 0 ) {
213+ if (diff <= 3){ return "Slight warming trend ahead."; }
214+ else if (diff > 3 && diff <= 10) { return "Moderate warming trend ahead."; }
215+ else { return "Considerable warming trend ahead."; }
216+ } else {
217+ if (diff >= -3){ return "Slight cooling trend ahead."; }
218+ else if (diff < -3 && diff <= -10) { return "Moderate cooling trend ahead."; }
219+ else { return "Considerable warming trend ahead."; }
220+ }
221+ }
222+ %>
223+ ```
224+
225+
226+ 7. Create ejs template file `index.ejs`, and inject partial files as follow.
183227
184228```c
185229 <!DOCTYPE html>
186230 <html lang="en">
187231
188232 <head>
189- <%- include(' ./partials/head' ); %>
233+ <%- include('./partials/head'); %>
234+ <%- include('./pages/utils'); %>
190235 </head>
191236
192237 <body class="container">
@@ -205,6 +250,8 @@ Partial files are pieces of reusable code segment that typically appear again an
205250 </html>
206251```
207252
253+ <br />
254+
208255<strong >Implement server-side routings </strong >
209256
2102571 . Add routing for the ` about ` page
0 commit comments