Course Selection Quiz
const courses = { humanities: { ART: ['ART 100', 'ART 112', 'ART 113', 'ART 200', 'ART 201'], ENG: ['ENG 185', 'ENG 210', 'ENG 211', 'ENG 212', 'ENG 217', 'ENG 220', 'ENG 230', 'ENG 237', 'ENG 242', 'ENG 270', 'ENG 271', 'ENG 272'], HIS: ['HIS 104', 'HIS 105'], HUM: ['HUM 101', 'HUM 202', 'HUM 205', 'HUM 241', 'HUM 242', 'HUM 243', 'HUM 248', 'HUM 260'], MUS: ['MUS 145', 'MUS 240'], PHI: ['PHI 101', 'PHI 103', 'PHI 105', 'PHI 110', 'PHI 122', 'PHI 204', 'PHI 210', 'PHI 215', 'PHI 220', 'PHI 232', 'PHI 233', 'PHI 238', 'PHI 244'], REL: ['REL 101', 'REL 200', 'REL 203', 'REL 205', 'REL 207', 'REL 261', 'REL 270', 'REL 273'], SPA: ['SPA 102', 'SPA 135', 'SPA 201', 'SPA 202', 'SPA 245'], THR: ['THR 135'] }, social: { AJS: ['AJS 123'], ANT: ['ANT 101', 'ANT 102', 'ANT 104', 'ANT 214', 'ANT 231'], ECE: ['ECE 234'], ECN: ['ECN 110'], EDU: ['EDU 200'], EXW: ['EXW 152'], GEO: ['GEO 101', 'GEO 102', 'GEO 105'], NTR: ['NTR 145'], POS: ['POS 100', 'POS 120'], PSY: ['PSY 101', 'PSY 234', 'PSY 245', 'PSY 277'], SOC: ['SOC 101', 'SOC 140', 'SOC 142', 'SOC 212', 'SOC 220', 'SOC 250'] }, americas: { AJS: ['AJS 290'], ANT: ['ANT 232'], ECN: ['ECN 235'], EDU: ['EDU 210'], ENG: ['ENG 240', 'ENG 241', 'ENG 245'], FMA: ['FMA 150'], HIS: ['HIS 131', 'HIS 132'], HUM: ['HUM 236'], LAW: ['LAW 290'], POS: ['POS 110'] } };
let currentQuestionIndex = 0; let userResponses = [];
function displayQuestion(index) { const question = questions[index]; const questionsDiv = document.getElementById('questions'); questionsDiv.innerHTML = `
${question.text}
`;
document.querySelectorAll('.option').forEach(option => { option.addEventListener('click', function() { document.querySelectorAll('.option').forEach(opt => opt.classList.remove('selected')); this.classList.add('selected'); }); }); }
function handleNext() { const selected = document.querySelector('.option.selected'); if (!selected && currentQuestionIndex < questions.length) { alert('Please select an option before continuing.'); return; } if (selected) { const questionIndex = currentQuestionIndex; const optionIndex = parseInt(selected.getAttribute('data-index')); userResponses.push(questions[questionIndex].options[optionIndex].tags); } currentQuestionIndex++; if (currentQuestionIndex < questions.length) { displayQuestion(currentQuestionIndex); document.getElementById('currentQuestion').textContent = currentQuestionIndex + 1; } else { showResults(); document.getElementById('nextButton').style.display = 'none'; } } function getRandomCourses(courseList, count, level) { const filteredCourses = courseList.filter(course => { const courseNumber = parseInt(course.split(' ')[1]); return level === 'lower' ? courseNumber < 200 : courseNumber >= 200; });
return shuffleArray(filteredCourses).slice(0, count); }
function shuffleArray(array) { for (let i = array.length - 1; i > 0; i--) { const j = Math.floor(Math.random() * (i + 1)); [array[i], array[j]] = [array[j], array[i]]; } return array; }
function showResults() { const results = document.getElementById('results'); const quiz = document.getElementById('quiz'); quiz.style.display = 'none'; results.style.display = 'block';
// Get all courses for each category const allHumanitiesCourses = Object.values(courses.humanities).flat(); const allSocialCourses = Object.values(courses.social).flat(); const allAmericasCourses = Object.values(courses.americas).flat();
// Get 2 lower-level and 2 upper-level courses for humanities const humanitiesLower = getRandomCourses(allHumanitiesCourses, 2, 'lower'); const humanitiesUpper = getRandomCourses(allHumanitiesCourses, 2, 'upper');
// Get 2 lower-level and 2 upper-level courses for social sciences const socialLower = getRandomCourses(allSocialCourses, 2, 'lower'); const socialUpper = getRandomCourses(allSocialCourses, 2, 'upper');
// Get 1 lower-level and 1 upper-level course for americas const americasLower = getRandomCourses(allAmericasCourses, 1, 'lower'); const americasUpper = getRandomCourses(allAmericasCourses, 1, 'upper');
results.innerHTML = `
Your Recommended Courses
Arts & Humanities Courses (Select 2 courses from different disciplines)
- ${course}
Social & Behavioral Sciences Courses (Select 2 courses from different disciplines)
- ${course}
Institutions in the Americas Courses (Select 1 course)
- ${course}
`; }
// Start the quiz displayQuestion(0);