-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
85 lines (68 loc) · 1.98 KB
/
main.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
document.getElementById("settings-button").addEventListener('click', openSettings);
function openSettings() {
// console.log("open settings")
document.getElementById("settings").classList.toggle("settings-open");
// console.log("settings")
}
//Getting Name
var userName = localStorage.getItem('receivedName');
function saveName() {
// console.log("savename!!");
localStorage.setItem('receivedName', userName);
// console.log("okay");
userName = localStorage.getItem('receivedName');
// console.log("completed: username == " + userName);
window.location.reload();
// console.log('come to here?');
}
function changeName() {
userName = document.getElementById("name-input").value;
//console.log("username: " + userName);
saveName();
}
function getGreeting() {
// console.log("getGreeting!");
if (userName == null) {
userName = "friend";
}
document.getElementById("greeting").innerHTML = `Hello, ${userName}. Have a great day!`;
}
getGreeting()
document.getElementById("submit").addEventListener("click", function(e) {
e.preventDefault()
// console.log("clicked!");
changeName();
});
//Clock
window.onload = startTime()
function startTime() {
var today = new Date();
var h = today.getHours();
var m = today.getMinutes();
m = checkTime(m);
document.getElementById('txt').innerHTML =
h + ":" + m ;
var t = setTimeout(startTime, 500);
}
function checkTime(i) {
if (i < 10) {i = "0" + i};
return i;
}
//TodoList
function newItem() {
var item = document.getElementById('input').value;
var ul = document.getElementById("list");
var li = document.createElement('li');
li.appendChild(document.createTextNode("- "+item));
ul.appendChild(li);
document.getElementById('input').value="";
li.onclick = removeItem;
}
document.body.onkeyup = function(e){
if(e.keyCode == 13){
newItem();
}
}
function removeItem(e) {
e.target.parentElement.removeChild(e.target);
}