Changed around line 1
+ // Sample university data
+ const universities = [
+ {
+ name: "Harvard University",
+ location: "USA",
+ tuition: 51000,
+ image: "harvard.jpg",
+ description: "Ivy League university in Cambridge, Massachusetts"
+ },
+ {
+ name: "University of Toronto",
+ location: "Canada",
+ tuition: 45000,
+ image: "toronto.jpg",
+ description: "Leading Canadian university in Ontario"
+ },
+ {
+ name: "Stanford University",
+ location: "USA",
+ tuition: 53000,
+ image: "stanford.jpg",
+ description: "Private research university in California"
+ },
+ {
+ name: "Universidad Nacional Autónoma de México",
+ location: "Mexico",
+ tuition: 800,
+ image: "unam.jpg",
+ description: "Public research university in Mexico City"
+ }
+ ];
+
+ // DOM Elements
+ const searchInput = document.getElementById('searchInput');
+ const searchButton = document.getElementById('searchButton');
+ const locationFilter = document.getElementById('location');
+ const tuitionFilter = document.getElementById('tuition');
+ const tuitionValue = document.getElementById('tuitionValue');
+ const universityGrid = document.getElementById('universityGrid');
+
+ // Event Listeners
+ searchButton.addEventListener('click', filterUniversities);
+ locationFilter.addEventListener('change', filterUniversities);
+ tuitionFilter.addEventListener('input', updateTuitionValue);
+ tuitionFilter.addEventListener('change', filterUniversities);
+
+ // Initial render
+ renderUniversities(universities);
+
+ function renderUniversities(data) {
+ universityGrid.innerHTML = data.map(university => `
+
+
+
+
${university.name}
+
${university.description}
+
Location: ${university.location}
+
Tuition: $${university.tuition.toLocaleString()}
+
+
+ `).join('');
+ }
+
+ function filterUniversities() {
+ const searchTerm = searchInput.value.toLowerCase();
+ const location = locationFilter.value;
+ const maxTuition = parseInt(tuitionFilter.value);
+
+ const filtered = universities.filter(university => {
+ const matchesSearch = university.name.toLowerCase().includes(searchTerm);
+ const matchesLocation = location === 'all' || university.location.toLowerCase() === location;
+ const matchesTuition = university.tuition <= maxTuition;
+ return matchesSearch && matchesLocation && matchesTuition;
+ });
+
+ renderUniversities(filtered);
+ }
+
+ function updateTuitionValue() {
+ tuitionValue.textContent = `$${parseInt(tuitionFilter.value).toLocaleString()}`;
+ }