-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
78 lines (45 loc) · 1.52 KB
/
index.js
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
const express = require('express');
const app =express();
const bodyParser= require("body-parser");
app.use(express.static(__dirname + '/public'));
app.set("view engine", "ejs");
app.use(bodyParser.urlencoded({ extended: true }));
app.listen(process.env.PORT || 3003, function() {
console.log("The server is running!");
})
var task = [];
var complete = [];
app.post("/addtask", function(req, res) {
var newTask = req.body.newtask;
task.push(newTask);
res.redirect("/");
});
app.post("/removetask", function(req, res) {
var completeTask = req.body.check;
//check for the “typeof” the different completed task, then add into the complete task
if (typeof completeTask === "string") {
complete.push(completeTask);
//check if the completed task already exits in the task when checked, then remove it
task.splice(task.indexOf(completeTask), 1);
} else if (typeof completeTask === "object") {
for (var i = 0; i < completeTask.length; i++) {
complete.push(completeTask[i]);
task.splice(task.indexOf(completeTask[i]), 1);
}
}
res.redirect("/");
});
app.post("/clear", function(req, res){
task = [];
complete = [];
res.redirect("/");
});
let date_ob= new Date();
let date=("0"+date_ob.getDate()).slice(-2);
let month=("0"+(date_ob.getMonth()+1)).slice(-2);
let year =date_ob.getFullYear();
console.log(date+"-"+month+"-"+year);
var Fdate=date+"-"+month+"-"+year;
app.get("/", function(req, res) {
res.render("index", { task: task, complete: complete,Fdate: Fdate});
});