You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
33 lines
757 B
33 lines
757 B
"use strict"; |
|
|
|
function main(formName) { |
|
let result = document.getElementById("result"); |
|
|
|
let year = document.forms[formName].elements[0].value; |
|
if (isNotNumber(year)) { |
|
result.textContent = "Ошибка: year не является числом!"; |
|
return; |
|
} |
|
|
|
if (!Number.isInteger(Number(year))) { |
|
result.textContent = "Ошибка: year должен быть целым!"; |
|
return; |
|
} |
|
|
|
result.textContent = "Результат: " + countFridays(year); |
|
} |
|
|
|
function countFridays(year) { |
|
let result = 0; |
|
|
|
for (let month = 1; month <= 12; month++) { |
|
let date = new Date(year, month, 13); |
|
result += date.getDay() == 5 ? 1 : 0; |
|
} |
|
|
|
return result; |
|
} |
|
|
|
function isNotNumber(val) { |
|
return val.replace(/\s/g, '').length === 0 || isNaN(val); |
|
}
|
|
|