-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
26 lines (21 loc) · 892 Bytes
/
Copy pathscript.js
File metadata and controls
26 lines (21 loc) · 892 Bytes
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
async function loadResources() {
const media = document.getElementById('media').value;
const difficulty = document.getElementById('difficulty').value;
const topic = document.getElementById('topic').value;
const res = await fetch('resources.json');
const allResources = await res.json();
const filtered = allResources.filter(r => {
return (!media || r.media === media) &&
(!difficulty || r.difficulty === difficulty) &&
(!topic || r.topic.includes(topic));
});
const results = document.getElementById('results');
results.innerHTML = '';
filtered.forEach(r => {
results.innerHTML += `<p><a href="${r.url}" target="_blank">${r.title}</a> — ${r.media}, ${r.difficulty}, ${r.topic.join(', ')}</p>`;
});
}
document.querySelectorAll('select').forEach(s => {
s.addEventListener('change', loadResources);
});
window.onload = loadResources;