-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIndex.js
65 lines (53 loc) · 1.42 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
65
//Counter value from localstorage
let counter = localStorage.getItem("counter");
document.getElementById("visitorsCount").innerHTML = counter;
if (counter === null) {
counter = 0;
localStorage.setItem("counter", counter);
}
document.getElementById("visitors").addEventListener("click", incrementNum);
function incrementNum() {
counter = ++counter;
localStorage.setItem("counter", counter);
document.getElementById("visitorsCount").innerHTML = counter;
}
//Getting date and time
let date = new Date();
let day = date.getDate();
const months = [
"January",
"February",
"March",
"April",
"May",
"June",
"July",
"August",
"September",
"October",
"November",
"December",
];
let todaysMonth = months[date.getMonth()];
let todaysYear = date.getFullYear();
document.getElementById("todaysDate").innerText =
day + " " + todaysMonth + " " + todaysYear;
//todo list
let todoList = document.getElementById("todoList");
let todoVal = todoList.value;
let todoSubmit = document.getElementById("todoSubmit");
let todoArr = [];
todoSubmit.onclick = function addTodos(e) {
e.preventDefault();
const todos = {
id: Date.now(),
title: todoList.value,
};
todoArr.push(todos);
console.log(todoArr);
localStorage.setItem("Lists", JSON.stringify(todoArr));
todoList.value = "";
};
let todoItems = document.getElementById("todoItems");
let todoData = localStorage.getItem("Lists");
todoItems.innerText = todoData;