From c2b4ed4b098ada9aa699f903bcd2c1f7c7acb7a9 Mon Sep 17 00:00:00 2001
From: Hong-Phuc Bui <hong-phuc.bui@htwsaar.de>
Date: Thu, 29 Oct 2026 11:46:52 +0100
Subject: [PATCH] Leapyear

---
 03-0-leapyear/index.html |   15 +++++++
 03-0-leapyear/leap.js    |   52 ++++++++++++++++++++++++++
 2 files changed, 67 insertions(+), 0 deletions(-)

diff --git a/03-0-leapyear/index.html b/03-0-leapyear/index.html
new file mode 100644
index 0000000..7cf8c72
--- /dev/null
+++ b/03-0-leapyear/index.html
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <title>Leapyear</title>
+</head>
+<body>
+
+<input type="text" id="year">
+<button type="button" id="ok">Ok</button>
+<p id="output"></p>
+<p id="error-output"></p>
+<script src="leap.js"></script>
+</body>
+</html>
\ No newline at end of file
diff --git a/03-0-leapyear/leap.js b/03-0-leapyear/leap.js
new file mode 100644
index 0000000..9e0d86b
--- /dev/null
+++ b/03-0-leapyear/leap.js
@@ -0,0 +1,52 @@
+/*
+* 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);
+    }
+})
\ No newline at end of file

--
Gitblit v1.10.0