-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
89 lines (76 loc) · 3.39 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!doctype html>
<html lang="pl" data-bs-theme="dark">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<title>Kiedy LS?</title>
<style>
body {
text-align: center;
}
h1 {
margin-top: 10px;
margin-bottom: 15px;
}
h2 {
margin-top: 15px;
}
</style>
</head>
<body>
<div class="container">
<h1>Kiedy LS?</h1>
<div class="col-lg-4 col-md-4 offset-lg-4 offset-md-4">
<form>
<div class="mb-3">
<label for="availableEpisodeInput" class="form-label">Dostępny odcinek</label>
<input type="number" class="form-control" id="availableEpisodeInput" placeholder="2137" required>
</div>
<div class="mb-3">
<label for="availableEpisodeDateInput" class="form-label">Data dostępnego odcinka</label>
<input type="date" class="form-control" id="availableEpisodeDateInput" required>
</div>
<div class="mb-3">
<label for="episodeInput" class="form-label">Jaki odcinek z przyszłości wariacie?</label>
<input type="number" class="form-control" id="episodeInput" placeholder="3000" required>
</div>
<button type="button" class="btn btn-primary" onclick="compute()">Widzisz mnie?</button>
</form>
</div>
<h2 id="result"></h2>
</div>
<script>
function compute() {
const availableEpisode = Number(document.getElementById("availableEpisodeInput").value)
const availableEpisodeDate = new Date(document.getElementById("availableEpisodeDateInput").value)
const futureEpisode = Number(document.getElementById("episodeInput").value)
console.log(availableEpisodeDate)
if (
availableEpisode === 0 ||
isNaN(availableEpisodeDate.getTime()) ||
futureEpisode === 0
) {
document.getElementById("result").innerHTML = 'Wszystkie pola muszą być uzupełnione'
document.getElementById("result").style = 'color: red'
throw new Error('Invalid form')
}
if (futureEpisode < availableEpisode) {
document.getElementById("result").innerHTML = 'Odcinek z przyszłości musi być... z przyszłości.'
document.getElementById("result").style = 'color: red'
throw new Error('Invalid future episode')
}
let episodesDifference = futureEpisode - availableEpisode
while (episodesDifference > 0) {
availableEpisodeDate.setDate(availableEpisodeDate.getDate() + 1)
if ((availableEpisodeDate.getDay() !== 6) && (availableEpisodeDate.getDay() !== 0)) {
episodesDifference--
}
}
const months = ["Styczeń", "Luty", "Marzec", "Kwiecień", "Maj", "Czerwiec", "Lipiec", "Sierpień", "Wczesień", "Październik", "Listopad", "Grudzień"];
document.getElementById("result").innerHTML = availableEpisodeDate.getDate() + " " + months[availableEpisodeDate.getMonth()] + " " + availableEpisodeDate.getFullYear()
}
</script>
</body>
</html>