first commit

main
root 2024-09-19 07:10:24 +02:00
commit 49f66f2ffc
3 changed files with 88 additions and 0 deletions

0
README.md Normal file
View File

19
index.html Normal file
View File

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Obliczanie daty Wielkanocy</title>
<link rel="icon" href="./favicon.png" type="image/png">
</head>
<body>
<label for="year">Wybierz rok (1900-2099):</label>
<input type="number" id="year" name="year" required>
<input type="button" value="Oblicz" onclick="calculate()">
<div id="result_div">
<p id="result"></p>
</div>
<script src="./index.js"></script>
</body>
</html>

69
index.js Normal file
View File

@ -0,0 +1,69 @@
function isNaturalNumber (str) {
var pattern = /^(0|([1-9]\d*))$/;
return pattern.test(str);
}
function calculate(){
let year = document.getElementById("year").value;
if (isNaturalNumber(year) == false){
document.getElementById("result").textContent = "Błąd. Podano nieodpowiedni ciąg znaków!"
}
else if (year < 1900 || year > 2099){
document.getElementById("result").textContent = "Błąd. Podano rok spoza zakresu 1900-2099!"
}
else{
let a, b, c, d, e, p, q, month;
p = 24;
q = 5;
month = 3;
a = year % 19;
b = year % 4;
c = year % 7;
d = ((19 * a) + p) % 30;
e = ((2 * b) + (4 * c) + (6 * d) + q) % 7;
result = d + e + 22;
if (result > 31){
result = result - 31;
month += 1;
}
if (result > 25 && month == 4){
result = result - 7;
}
document.getElementById("result").textContent = `Data wielkanocy: ${result}.0${month}.${year}`;
}
}
// d
// function calculate() {
// let year = document.getElementById("year").value;
// if (isNaturalNumber(year) == false) {
// document.getElementById("result").textContent = "Błąd. Podano nieodpowiedni ciąg znaków!"
// }
// else if (year < 1 || year > 5000) {
// document.getElementById("result").textContent = "Błąd. Podano rok spoza zakresu 1-5000!"
// }
// else {
// let a, b, c, d, e, f, g, h, i, k, l, m, month, day;
// a = year % 19;
// b = Math.floor(year / 100);
// c = year % 100;
// d = Math.floor(b / 4);
// e = b % 4;
// f = Math.floor((b + 8) / 25);
// g = Math.floor((b - f + 1) / 3);
// h = (19 * a + b - d - g + 15) % 30;
// i = Math.floor(c / 4);
// k = c % 4;
// l = (32 + 2 * e + 2 * i - h - k) % 7;
// m = Math.floor((a + 11 * h + 22 * l) / 451);
// month = Math.floor((h + l - 7 * m + 114) / 31);
// day = ((h + l - 7 * m + 114) % 31) + 1;
// document.getElementById("result").textContent = `Data wielkanocy: ${day.toString().padStart(2, '0')}.${month.toString().padStart(2, '0')}.${year}`;
// }
// }