Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions dom-merge-conflict/tasks/buttons-and-counter/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,40 @@ function increment(node) {
let current = node.textContent;
node.textContent = Number(current) + 1;
}

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 increment to increase the count by one and
Press decrement to decrease the count by on.</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 decrementButton = document.createElement("decrementButton");
decrementButton.innerHTML = `<button id="decrement">Decrement</button>`;
main.appendChild(decrementButton); */
const button = body.querySelector("#increment");
const counter = body.querySelector("#counter");
button.addEventListener("click", () => {
increment(counter);
});

const decBtn =body.querySelector("#decrement");
decBtn.addEventListener("click", ()=>{
decrement(counter);
});
return body;
}