<button id="calculate">Calculate</button>
<button id="clear">Clear</button>
<pre id="results"></pre>
const results = document.querySelector("#results");
function calculate() {
for (let i = 1; i < 10; i++) {
const newResult = `${i} x ${i} = ${i * i}`;
results.textContent += `${newResult}\n`;
}
results.textContent += "\nFinished!\n\n";
}
const calculateBtn = document.querySelector("#calculate");
const clearBtn = document.querySelector("#clear");
calculateBtn.addEventListener("click", calculate);
clearBtn.addEventListener("click", () => (results.textContent = ""));
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.