60 lines
3.0 KiB
JavaScript
60 lines
3.0 KiB
JavaScript
// Данные примерные: их легко заменить на реальные (массив UNIVERSITIES).
|
||
const UNIVERSITIES = [
|
||
{ name: "КазНУ им. аль-Фараби", specialty: "Прикладная математика", city: "Алматы", min: 162, budget: 85, scholarship: 14500 },
|
||
{ name: "Самаркандский гос. университет", specialty: "IT и разработка ПО", city: "Самарканд", min: 154, budget: 60, scholarship: 12000 },
|
||
{ name: "КазНТУ им. Т. Рысқұлова", specialty: "Программная инженерия", city: "Алматы", min: 148, budget: 72, scholarship: 13000 },
|
||
{ name: "Eurasian National University", specialty: "Международные отношения", city: "Астана", min: 141, budget: 38, scholarship: 15000 },
|
||
{ name: "КазНУ им. аль-Фараби", specialty: "Медицина (лечебное дело)", city: "Алматы", min: 171, budget: 96, scholarship: 16000 },
|
||
{ name: "АУ «Сарыарка»", specialty: "Психология", city: "Караганда", min: 139, budget: 25, scholarship: 10500 },
|
||
];
|
||
|
||
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);
|