|
| 1 | +document.addEventListener('DOMContentLoaded', () => { |
| 2 | + fetch('test.json') // Adjust this if the JSON file is in a different location |
| 3 | + .then(response => response.json()) |
| 4 | + .then(data => initializePage(data)); |
| 5 | +}); |
| 6 | + |
| 7 | +let courseData = {}; |
| 8 | + |
| 9 | +function initializePage(data) { |
| 10 | + courseData = data; // Save the JSON data |
| 11 | + const courseSelect = document.getElementById('courseSelect'); |
| 12 | + |
| 13 | + // Populate the courses dropdown |
| 14 | + Object.keys(courseData).forEach(courseKey => { |
| 15 | + const option = document.createElement('option'); |
| 16 | + option.value = courseKey; |
| 17 | + option.textContent = courseKey.toUpperCase(); |
| 18 | + courseSelect.appendChild(option); |
| 19 | + }); |
| 20 | +} |
| 21 | + |
| 22 | +function populateDomains() { |
| 23 | + const courseSelect = document.getElementById('courseSelect'); |
| 24 | + const selectedCourse = courseSelect.value; |
| 25 | + const domainSelect = document.getElementById('domainSelect'); |
| 26 | + domainSelect.innerHTML = '<option value="" disabled selected>Select a Domain</option>'; // Reset domain options |
| 27 | + |
| 28 | + if (selectedCourse && courseData[selectedCourse]) { |
| 29 | + const domains = courseData[selectedCourse].domains; |
| 30 | + |
| 31 | + Object.keys(domains).forEach(domainKey => { |
| 32 | + const option = document.createElement('option'); |
| 33 | + option.value = domainKey; |
| 34 | + option.textContent = domainKey; |
| 35 | + domainSelect.appendChild(option); |
| 36 | + }); |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +function showRoadmap() { |
| 41 | + const courseSelect = document.getElementById('courseSelect'); |
| 42 | + const domainSelect = document.getElementById('domainSelect'); |
| 43 | + const selectedCourse = courseSelect.value; |
| 44 | + const selectedDomain = domainSelect.value; |
| 45 | + const roadmapContainer = document.getElementById('roadmap'); |
| 46 | + const referenceLink = document.getElementById('referenceLink'); |
| 47 | + |
| 48 | + roadmapContainer.innerHTML = ''; // Clear previous roadmap |
| 49 | + |
| 50 | + if (selectedCourse && selectedDomain && courseData[selectedCourse].domains[selectedDomain]) { |
| 51 | + const roadmap = courseData[selectedCourse].domains[selectedDomain].roadmap; |
| 52 | + const reference = courseData[selectedCourse].domains[selectedDomain].reference; |
| 53 | + |
| 54 | + roadmap.forEach(step => { |
| 55 | + const listItem = document.createElement('li'); |
| 56 | + listItem.textContent = step; |
| 57 | + roadmapContainer.appendChild(listItem); |
| 58 | + }); |
| 59 | + |
| 60 | + referenceLink.href = reference; |
| 61 | + referenceLink.style.display = 'block'; |
| 62 | + } |
| 63 | +} |
0 commit comments