sdelay-sayt-chtob-abiturient/script.js

62 lines
3.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Данные примерные: их легко заменить на реальные (массив UNIVERSITIES).
const UNIVERSITIES = [
{ name: "КазНУ им. аль-Фараби", specialty: "Прикладная математика", city: "Алматы", min: 162, budget: 85, scholarship: 14500 },
{ name: "КазНУ им. аль-Фараби", specialty: "Фундаментальная математика", city: "Алматы", min: 158, budget: 40, scholarship: 14500 },
{ name: "КазНУ им. аль-Фараби", specialty: "Математика и информатика", city: "Алматы", min: 153, budget: 55, scholarship: 14000 },
{ name: "KazNU Kazakh-British Technical University", specialty: "Математическое моделирование", city: "Астана", min: 156, budget: 30, scholarship: 13500 },
{ name: "Евразийский национальный университет", specialty: "Дискретная математика", city: "Астана", min: 150, budget: 35, scholarship: 13000 },
{ name: "КазНТУ им. Т. Рысқұлова", specialty: "Прикладная математика", city: "Алматы", min: 146, budget: 68, scholarship: 12500 },
{ name: "АУ «Сарыарка»", specialty: "Математика", city: "Караганда", min: 138, budget: 25, scholarship: 10000 },
{ name: "ЮЗГУ", specialty: "Математика и статистика", city: "Костанай", min: 132, budget: 30, scholarship: 9500 },
];
const body = document.getElementById("uni-body");
const note = document.getElementById("uni-note");
function renderTable(rows) {
if (!body) return;
body.innerHTML = "";
for (const r of rows) {
const tr = document.createElement("tr");
tr.innerHTML =
'<td>' + r.name + "</td>" +
'<td>' + r.specialty + "</td>" +
'<td>' + r.city + "</td>" +
'<td class="num">' + r.min + "</td>" +
'<td class="num">' + r.budget + "</td>" +
'<td class="num">' + r.scholarship.toLocaleString("ru-RU") + " тг</td>";
body.appendChild(tr);
}
note.textContent = rows.length
? "Показано вариантов: " + rows.length + "."
: "Ничего не нашлось — попробуй другой запрос или сбрось балл.";
}
function fmt(v) {
return v == null ? "" : String(v).trim().toLowerCase();
}
document.getElementById("btn-search")?.addEventListener("click", function () {
const q = fmt(document.getElementById("f-specialty").value);
const score = parseInt(document.getElementById("f-score").value, 10);
let rows = UNIVERSITIES.filter(function (u) {
const okQ = !q || u.specialty.toLowerCase().includes(q) || u.name.toLowerCase().includes(q);
const okScore = isNaN(score) || u.min <= score;
return okQ && okScore;
});
if (!isNaN(score)) rows = rows.slice().sort(function (a, b) { return a.min - b.min; });
renderTable(rows);
document.getElementById("search-note").hidden = true;
document.getElementById("universities").scrollIntoView({ behavior: "smooth" });
});
(function () {
const avg = Math.round(UNIVERSITIES.reduce(function (s, u) { return s + u.min; }, 0) / UNIVERSITIES.length);
const el = document.getElementById("prog-avg");
const num = document.getElementById("prog-avg-num");
if (el) el.style.width = Math.min(100, Math.round(avg / 2)) + "%";
if (num) num.textContent = avg;
})();
renderTable(UNIVERSITIES);