feat/excersices #7

Open
saucedo.facundo wants to merge 3 commits from saucedo.facundo/clase-11-ejercicio-integrador:feat/excersices into main
Showing only changes of commit c1cd76ecb0 - Show all commits

View File

@@ -33,5 +33,36 @@ const renderTable = (books) => {
}
}
const validateForm = (tittle, author, year, score) => {
if (!tittle || !author || !year || !score) return false;
if (year < 0 || score < 0 || score > 10) return false;
return true;
}
const addBook = (tittle, author, year, score) => {
if(!validateForm(tittle, author, year, score)) {
alert('Datos invalidos');
return;
}
books.push({tittle: tittle, year: Number(year), score: Number(score), author: author});
renderTable(books);
}
document.getElementById('boton-agregar').addEventListener('click', () => {
const tittle = document.getElementById('titulo').value;
const author = document.getElementById('autor').value;
const year = document.getElementById('anio').value;
const score = document.getElementById('calificacion').value;
addBook(tittle, author, year, score);
document.getElementById('titulo').value = "";
document.getElementById('autor').value = "";
document.getElementById('anio').value = "";
document.getElementById('calificacion').value = "";
})
renderTable(books);