-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtask-2.html
More file actions
459 lines (423 loc) · 17.3 KB
/
Copy pathtask-2.html
File metadata and controls
459 lines (423 loc) · 17.3 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>✨ Стилистическое преобразование чисел ✨</title>
<style>
* {
box-sizing: border-box;
}
body {
background: linear-gradient(145deg, #0b0f1c 0%, #1a1f33 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
font-family: 'Segoe UI', 'Consolas', monospace;
margin: 0;
padding: 16px;
color: #e3e9ff;
}
.card {
background: rgba(20, 28, 50, 0.85);
backdrop-filter: blur(12px);
border: 1px solid #3d4b7c;
border-radius: 42px;
padding: 32px 28px;
max-width: 700px;
width: 100%;
box-shadow: 0 20px 40px rgba(0, 0, 0, 0.6), 0 0 0 2px #2a3560 inset;
transition: all 0.2s;
}
h1 {
text-align: center;
font-weight: 400;
letter-spacing: 3px;
text-transform: uppercase;
font-size: 2.1rem;
margin-top: 0;
margin-bottom: 20px;
color: #ffd966;
text-shadow: 0 0 8px #ffb347;
word-break: break-word;
}
.sub {
text-align: center;
margin-bottom: 28px;
font-style: italic;
color: #b4c2f0;
border-bottom: 1px dashed #4e6190;
padding-bottom: 16px;
}
.console-badge {
background: #0e121f;
padding: 6px 16px;
border-radius: 60px;
display: inline-block;
margin-bottom: 10px;
font-family: 'Consolas', monospace;
border: 1px solid #5f73b0;
color: #b7e0ff;
}
.btn-group {
display: flex;
justify-content: center;
margin: 30px 0 20px;
}
.glow-btn {
background: #1e2b4e;
border: 2px solid #6d8ae0;
color: #f0f4ff;
font-size: 1.4rem;
font-weight: bold;
padding: 16px 32px;
border-radius: 60px;
cursor: pointer;
box-shadow: 0 8px 0 #0b121e, 0 0 15px #3f66cc;
transition: 0.1s ease;
letter-spacing: 2px;
font-family: inherit;
backdrop-filter: blur(5px);
background: rgba(40, 60, 110, 0.7);
text-transform: uppercase;
}
.glow-btn:hover {
background: #2f4280;
box-shadow: 0 6px 0 #0b121e, 0 0 25px #5f8aff;
transform: translateY(2px);
border-color: #a3bbff;
}
.glow-btn:active {
transform: translateY(8px);
box-shadow: 0 0 0 #0b121e, 0 0 30px #8aa2ff;
}
.result-panel {
background: #0c1020c9;
border-radius: 28px;
padding: 22px 20px;
margin-top: 25px;
border: 1px solid #5769a8;
box-shadow: inset 0 0 10px #00000055, 0 6px 0 #080b14;
}
.info-row {
display: flex;
align-items: baseline;
flex-wrap: wrap;
padding: 10px 5px;
border-bottom: 1px solid #35416e;
font-size: 1.2rem;
}
.info-label {
width: 160px;
font-weight: 600;
color: #b7cbff;
text-shadow: 0 0 5px #2f4bb0;
}
.info-value {
font-family: 'Consolas', 'Monaco', monospace;
color: #ffecb3;
font-size: 1.3rem;
word-break: break-word;
}
.console-hint {
margin-top: 16px;
font-size: 0.95rem;
color: #9aabdf;
background: #131b30;
padding: 12px 16px;
border-radius: 20px;
display: flex;
align-items: center;
gap: 12px;
border-left: 6px solid #ffbe5c;
}
.console-hint i {
font-style: normal;
font-size: 1.8rem;
}
.footnote {
margin-top: 8px;
text-align: right;
opacity: 0.8;
}
.star-preview {
font-family: monospace;
font-size: 0.7rem;
line-height: 1.2;
color: #ffe5a3;
}
</style>
</head>
<body>
<div class="card">
<h1>✦ ЧИСЛА ИЗ ЗВЁЗД ✦</h1>
<div class="sub">стилистическое преобразование · электронное табло</div>
<div style="text-align: center;">
<span class="console-badge">⚡ ОТКРОЙ КОНСОЛЬ (F12) ⚡</span>
</div>
<div class="btn-group">
<button class="glow-btn" id="startBtn">🎂 ВВЕСТИ ДАТУ</button>
</div>
<div class="result-panel" id="resultPanel">
<div class="info-row">
<span class="info-label">📅 День недели</span>
<span class="info-value" id="weekdayDisplay">—</span>
</div>
<div class="info-row">
<span class="info-label">🗓️ Високосный год</span>
<span class="info-value" id="leapDisplay">—</span>
</div>
<div class="info-row">
<span class="info-label">🎂 Возраст (полных лет)</span>
<span class="info-value" id="ageDisplay">—</span>
</div>
<div class="info-row">
<span class="info-label">📟 Дата (звёзды в консоли)</span>
<span class="info-value" id="dateRawDisplay">—</span>
</div>
</div>
<div class="console-hint">
<i>🖥️</i>
<span>В консоли появится дата в формате <strong>ДД ММ ГГГГ</strong><br>
<span style="font-size:0.9rem;">каждая цифра — из звёздочек (*) как на электронном табло</span></span>
</div>
<div class="footnote">
<span class="star-preview"> *** * *** </span>
</div>
</div>
<script>
(function(){
"use strict";
// ----- Представление цифр 0-9 звёздочками (5 строк, ширина 5 символов) -----
const DIGIT_PATTERNS = {
'0': [
' *** ',
'* *',
'* *',
'* *',
' *** '
],
'1': [
' * ',
' ** ',
' * ',
' * ',
' *** '
],
'2': [
' *** ',
'* *',
' * ',
' * ',
'*****'
],
'3': [
' *** ',
'* *',
' **',
'* *',
' *** '
],
'4': [
' * ',
' ** ',
' * * ',
'*****',
' * '
],
'5': [
'*****',
'* ',
'**** ',
' *',
'**** '
],
'6': [
' *** ',
'* ',
'**** ',
'* *',
' *** '
],
'7': [
'*****',
' *',
' * ',
' * ',
' * '
],
'8': [
' *** ',
'* *',
' *** ',
'* *',
' *** '
],
'9': [
' *** ',
'* *',
' ****',
' *',
' *** '
]
};
// Дополнительно: пробел между блоками (ширина 1 символ)
const SPACE_COL = [' ', ' ', ' ', ' ', ' '];
// ----- Функция для форматирования даты в звёздочное табло -----
function formatDateAsStars(day, month, year) {
// Приводим к строкам с ведущими нулями: дд, мм, гггг
const dayStr = String(day).padStart(2, '0');
const monthStr = String(month).padStart(2, '0');
const yearStr = String(year).padStart(4, '0');
// Собираем полную строку из цифр и пробелов: "ДД ММ ГГГГ"
const sequence = `${dayStr} ${monthStr} ${yearStr}`;
const lines = ['', '', '', '', '']; // 5 строк
for (let i = 0; i < sequence.length; i++) {
const ch = sequence[i];
let pattern;
if (ch >= '0' && ch <= '9') {
pattern = DIGIT_PATTERNS[ch];
} else if (ch === ' ') {
pattern = SPACE_COL;
} else {
// на всякий случай (но там только цифры и пробел)
pattern = SPACE_COL;
}
for (let row = 0; row < 5; row++) {
lines[row] += pattern[row];
}
}
return lines.join('\n');
}
// ----- Определение дня недели (на русском) -----
function getDayOfWeek(day, month, year) {
// month: 1-12, в Date месяц от 0 до 11
const date = new Date(year, month - 1, day);
const daysRu = [
'воскресенье', 'понедельник', 'вторник', 'среда',
'четверг', 'пятница', 'суббота'
];
return daysRu[date.getDay()];
}
// ----- Проверка на високосный год -----
function isLeapYear(year) {
return (year % 4 === 0 && year % 100 !== 0) || (year % 400 === 0);
}
// ----- Вычисление возраста (полных лет) на текущую дату -----
function calculateAge(birthDate) {
const today = new Date();
let age = today.getFullYear() - birthDate.getFullYear();
const monthDiff = today.getMonth() - birthDate.getMonth();
const dayDiff = today.getDate() - birthDate.getDate();
// Если день рождения в этом году ещё не наступил, уменьшаем возраст
if (monthDiff < 0 || (monthDiff === 0 && dayDiff < 0)) {
age--;
}
return age;
}
// ----- Валидация даты (проверка реального существования) -----
function isValidDate(day, month, year) {
// Месяц 1-12
if (month < 1 || month > 12) return false;
// Год: допустим от 1900 до текущего + небольшой запас (не будущее)
const currentYear = new Date().getFullYear();
if (year < 1900 || year > currentYear) return false;
// Количество дней в месяце
const daysInMonth = new Date(year, month, 0).getDate();
if (day < 1 || day > daysInMonth) return false;
// Дополнительно: дата не может быть в будущем
const birthDate = new Date(year, month - 1, day);
const today = new Date();
today.setHours(0, 0, 0, 0);
if (birthDate > today) return false;
return true;
}
// ----- Основная функция, запускается по кнопке -----
function runProgram() {
// Запрос дня
let dayInput = prompt('Введите день рождения (число):', '15');
if (dayInput === null) return;
dayInput = dayInput.trim();
if (dayInput === '') {
alert('День не может быть пустым.');
return;
}
const day = Number(dayInput);
if (!Number.isInteger(day) || day < 1 || day > 31) {
alert('Некорректный день. Введите число от 1 до 31.');
return;
}
// Запрос месяца
let monthInput = prompt('Введите месяц рождения (число):', '5');
if (monthInput === null) return;
monthInput = monthInput.trim();
if (monthInput === '') {
alert('Месяц не может быть пустым.');
return;
}
const month = Number(monthInput);
if (!Number.isInteger(month) || month < 1 || month > 12) {
alert('Некорректный месяц. Введите число от 1 до 12.');
return;
}
// Запрос года
let yearInput = prompt('Введите год рождения (например, 1990):', '1995');
if (yearInput === null) return;
yearInput = yearInput.trim();
if (yearInput === '') {
alert('Год не может быть пустым.');
return;
}
const year = Number(yearInput);
const currentYear = new Date().getFullYear();
if (!Number.isInteger(year) || year < 1900 || year > currentYear) {
alert(`Год должен быть целым числом от 1900 до ${currentYear}.`);
return;
}
// Проверка существования даты и не будущее
if (!isValidDate(day, month, year)) {
alert('❌ Такой даты не существует или она в будущем. Проверьте правильность.');
return;
}
// ---- ВЫЧИСЛЕНИЯ ----
const weekday = getDayOfWeek(day, month, year);
const leap = isLeapYear(year);
const birthDate = new Date(year, month - 1, day);
const age = calculateAge(birthDate);
// Формируем дату для звёздочного вывода
const starArt = formatDateAsStars(day, month, year);
// Форматированная строка ДД.ММ.ГГГГ для обычного отображения
const formattedDate = `${String(day).padStart(2, '0')}.${String(month).padStart(2, '0')}.${year}`;
// ----- ОТОБРАЖЕНИЕ В ИНТЕРФЕЙСЕ -----
document.getElementById('weekdayDisplay').textContent = weekday;
document.getElementById('leapDisplay').textContent = leap ? '✅ Да, високосный' : '❌ Нет, невисокосный';
document.getElementById('ageDisplay').textContent = `${age} ${getYearDeclension(age)}`;
document.getElementById('dateRawDisplay').textContent = formattedDate;
// ----- ВЫВОД В КОНСОЛЬ (как требует задание) -----
console.clear(); // опционально, чтобы не мешать старые выводы
console.log('%c🎂 ДАТА РОЖДЕНИЯ В СТИЛЕ ЭЛЕКТРОННОГО ТАБЛО 🎂', 'font-size: 18px; font-weight: bold; color: #ffd966; background: #0e162c; padding: 6px 12px; border-radius: 30px;');
console.log(`\n📌 ${formattedDate}\n`);
console.log(starArt);
console.log('\n%c✨ День недели: ' + weekday, 'color: #aad0ff; font-size: 14px;');
console.log('%c🗓️ Високосный год: ' + (leap ? 'Да' : 'Нет'), 'color: #b0ffb0;');
console.log('%c🧑 Возраст: ' + age + ' ' + getYearDeclension(age), 'color: #ffb77c; font-size: 14px;');
console.log('%c═══════════════════════════════════', 'color: #6f8ae0');
}
// Вспомогательная функция склонения "год/года/лет"
function getYearDeclension(age) {
const lastDigit = age % 10;
const lastTwo = age % 100;
if (lastTwo >= 11 && lastTwo <= 19) return 'лет';
if (lastDigit === 1) return 'год';
if (lastDigit >= 2 && lastDigit <= 4) return 'года';
return 'лет';
}
// Привязка к кнопке
document.getElementById('startBtn').addEventListener('click', runProgram);
// Небольшая подсказка в консоль при загрузке
console.log('%c⚡ Нажмите кнопку "ВВЕСТИ ДАТУ", чтобы начать ⚡', 'background: #1e2f5e; color: #fae467; font-size: 16px; padding: 8px 16px; border-radius: 20px;');
})();
</script>
</body>
</html>