<meta charset = "utf-8">
<h1>Tabla de Multiplicar</h1>
<label for="in">Ingresa el número</label>
<input type="text" id="in" name="num" value="2">
<button onclick=tablaMultiplicar()>Calcular</button>
<button onclick=limpiar()>Limpiar</button>
<div id="tb"></div>
<script>
const tablaMultiplicar = () => {
let num = document.getElementById("in").value;
for(let i = 0; i <= 12; i++){
let p = document.createElement("p");
p.innerText = `${num} x ${i} = ${num*i}`;
document.getElementById("tb").appendChild(p);
}
}
const limpiar = () => {
document.getElementById("tb").innerHTML = "";
document.getElementById("in").value = "";
document.getElementById("in").focus();
}
</script>