const formulario = document.getElementById('formulario');
const lista = document.getElementById('lista');
const totalSpan = document.getElementById('total');
deje registros = [];
función actualizar() {
lista.innerHTML = '';
sea total = 0;
registros.forEach((r, i) => {
const sub = r.cantidad * r.precio;
total += sub;
const div = document.createElement('div');
div.className = 'registro';
div.innerHTML = `
${r.fecha}
${r.cantidad} x $${r.precio} = $${sub.toFixed(2)}
`;
lista.appendChild(div);
});
totalSpan.textContent = total.toFixed(2);
}
formulario.addEventListener('enviar', (e) => {
e.preventDefault();
const fecha = document.getElementById('fecha').value;
const cantidad = parseFloat(document.getElementById('cantidad').value);
const precio = parseFloat(document.getElementById('precio').value);
registros.push({ fecha, cantidad, precio });
actualizar();
formulario.reset();
});
document.getElementById('fecha').valueAsDate = new Date();