Nulstil øvelsen
<div> <input type="number" id="n" value="0"> <button commandfor="n" command="--add" value="-10">-10</button> <button commandfor="n" command="--add" value="-1">-1</button> <button commandfor="n" command="--add" value="1">+1</button> <button commandfor="n" command="--add" value="10">+10</button> </div>
const input = document.querySelector("#n");
input.addEventListener("command", (e) => {
if (e.command === "--add") {
e.target.value = Number(e.target.value) + Number(e.source.value);
}
});