Skip to content

Commit 9e48c29

Browse files
committed
proof-of-concept commit
0 parents  commit 9e48c29

File tree

3 files changed

+108
-0
lines changed

3 files changed

+108
-0
lines changed

index.html

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<link rel="stylesheet" href="style.css">
8+
<title>Today I Learned</title>
9+
</head>
10+
<body>
11+
<div class="container">
12+
<div class="inputs">
13+
<textarea name="text-for-thing" class="text-for-thing" id="text-for-thing" cols="30" rows="10"></textarea>
14+
<input type="button" class="add-item" value="Add Item">
15+
<input type="button" class="remove-all" value="Remove All">
16+
</div>
17+
<div class="til"></div>
18+
</div>
19+
<script src="script.js"></script>
20+
</body>
21+
</html>

script.js

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
let itemKey = localStorage.length;
2+
const til = document.querySelector('.til');
3+
const list = document.createElement('ul');
4+
const textarea = document.querySelector('.text-for-thing');
5+
const submit = document.querySelector('.add-item');
6+
const removeAll = document.querySelector('.remove-all');
7+
const listItems = list.querySelectorAll('li');
8+
list.classList.add('things-i-learned');
9+
til.appendChild(list);
10+
11+
for (let i = 0; i < localStorage.length; i++) {
12+
const element = document.createElement('li');
13+
element.classList.add('thing-i-learned');
14+
list.appendChild(element);
15+
element.innerHTML = localStorage[i];
16+
itemKey = localStorage.length + 1;
17+
}
18+
19+
submit.addEventListener('click', function() {
20+
const text = textarea.value;
21+
const element = document.createElement('li');
22+
element.classList.add('thing-i-learned');
23+
element.innerHTML = text;
24+
list.appendChild(element);
25+
localStorage.setItem(itemKey, text);
26+
itemKey = localStorage.length + 1;
27+
});
28+
29+
removeAll.addEventListener('click', function() {
30+
localStorage.clear();
31+
list.querySelectorAll('li').forEach(item => {
32+
item.remove();
33+
})
34+
})
35+
36+

style.css

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
*, *::after, *::before {
2+
box-sizing: border-box;
3+
}
4+
5+
body {
6+
margin: 0;
7+
}
8+
9+
.container {
10+
display: flex;
11+
min-height: 100vh;
12+
}
13+
14+
.container > * {
15+
width: 50%;
16+
padding: 1rem;
17+
}
18+
19+
.inputs {
20+
background-color: beige;
21+
}
22+
23+
.til {
24+
background-color: azure;
25+
}
26+
27+
.text-for-thing {
28+
width: 100%;
29+
padding: 1rem;
30+
}
31+
32+
[type="button"] {
33+
width: 100%;
34+
padding: 1rem;
35+
margin-top: 1rem;
36+
cursor: pointer;
37+
}
38+
39+
.things-i-learned {
40+
padding-left: 0;
41+
}
42+
43+
.thing-i-learned {
44+
list-style: none;
45+
border: 1px solid darkkhaki;
46+
padding: 1rem;
47+
}
48+
49+
.thing-i-learned + .thing-i-learned {
50+
margin-top: 1rem;
51+
}

0 commit comments

Comments
 (0)