-
-
Notifications
You must be signed in to change notification settings - Fork 408
Expand file tree
/
Copy pathapp.js
More file actions
44 lines (37 loc) · 1.25 KB
/
app.js
File metadata and controls
44 lines (37 loc) · 1.25 KB
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
//increments the number in a node's text
function increment(node) {
let current = node.textContent;
node.textContent = Number(current) + 1;
}
// decrements the number in a node's text
function decrement(node) {
let current = node.textContent;
node.textContent = Number(current) - 1;
}
export function App() {
const body = document.createElement("body");
const header = document.createElement("header");
header.innerHTML = `
<h1>Number Counter</h1>
<p>A simple counter. Press increment to increase the count by one.</p>
<p>A simple counter. Press decrement to decrease the count by one.</p>
`;
body.appendChild(header);
const main = document.createElement("main");
main.innerHTML = `
<p id="counter" data-testid="counter">0</p>
<button id="increment">Increment</button>
<button id="decrement">Decrement</button>
`;
body.appendChild(main);
const incrementButton = body.querySelector("#increment");
const decrementButton = body.querySelector("#decrement");
const counter = body.querySelector("#counter");
incrementButton.addEventListener("click", () => {
increment(counter);
});
decrementButton.addEventListener("click", () => {
decrement(counter);
});
return body;
}