diff --git a/dom-merge-conflict/tasks/buttons-and-counter/src/app.js b/dom-merge-conflict/tasks/buttons-and-counter/src/app.js index af608eb6..772eb97c 100644 --- a/dom-merge-conflict/tasks/buttons-and-counter/src/app.js +++ b/dom-merge-conflict/tasks/buttons-and-counter/src/app.js @@ -1,31 +1,14 @@ -//increments the number in a node's text -function increment(node) { - let current = node.textContent; - node.textContent = Number(current) + 1; -} +import { createHeader } from "./header.js"; +import { createMain } from "./main.js"; export function App() { const body = document.createElement("body"); - const header = document.createElement("header"); - header.innerHTML = ` -
A simple counter. Press increment to increase the count by one.
- `; - body.appendChild(header); + const header = createHeader(); + const main = createMain(); - const main = document.createElement("main"); - main.innerHTML = ` -0
- - `; + body.appendChild(header); body.appendChild(main); - const button = body.querySelector("#increment"); - const counter = body.querySelector("#counter"); - button.addEventListener("click", () => { - increment(counter); - }); - return body; } diff --git a/dom-merge-conflict/tasks/buttons-and-counter/src/header.js b/dom-merge-conflict/tasks/buttons-and-counter/src/header.js new file mode 100644 index 00000000..891ee14e --- /dev/null +++ b/dom-merge-conflict/tasks/buttons-and-counter/src/header.js @@ -0,0 +1,8 @@ +export function createHeader() { + const header = document.createElement("header"); + header.innerHTML = ` +A simple counter. Press increment to increase the count by one.
+ `; + return header; + } diff --git a/dom-merge-conflict/tasks/buttons-and-counter/src/main.js b/dom-merge-conflict/tasks/buttons-and-counter/src/main.js new file mode 100644 index 00000000..5fc13149 --- /dev/null +++ b/dom-merge-conflict/tasks/buttons-and-counter/src/main.js @@ -0,0 +1,22 @@ +function increment(node) { + const current = node.textContent; + node.textContent = Number(current) + 1; + } + + export function createMain() { + const main = document.createElement("main"); + main.innerHTML = ` +0
+ + `; + + const button = main.querySelector("#increment"); + const counter = main.querySelector("#counter"); + + button.addEventListener("click", () => { + increment(counter); + }); + + return main; + } +