/* * Schaltjahr * durch 4 teilbar * wenn das jahr durch 100 teilbar dann ist das jahr kein * schaltjahr aber wenn das Jahr durch 400 teilbar dann das jahr ist * wiederum ein schaltjahr * */ const isLeapyear = (year) => ((year % 4) === 0) && (year % 100 !== 0) || (year % 400 === 0); const validateInputYear = (inputYear) => { const year = Number(inputYear); if(Number.isNaN(year)) { throw new Error("Invalid input"); } if(! Number.isInteger(year)) { throw new Error("Invalid input"); } if (year < 1582) { throw new Error("Invalid year"); } } const resetOutput = () => { const output = document.getElementById("output"); const errorContainer = document.getElementById("error-output"); errorContainer.textContent = ""; output.textContent = ""; } const showUserError = (error) => { const errorContainer = document.getElementById("error-output"); errorContainer.textContent = e.message } document.getElementById("ok").addEventListener("click", () => { const year = document.getElementById("year").value; const output = document.getElementById("output"); resetOutput(); try { validateInputYear(year); if (isLeapyear(year)) { output.textContent = "ist ein Schaltjahr"; }else { output.textContent = "ist KEIN Schaltjahr"; } }catch (e) { showUserError(e); } })