In this lesson, you will learn how to build course list, search, and filters for your Student Learning Dashboard.
A student learning dashboard helps you manage your courses effectively. Imagine you have multiple courses online. You want to find a specific course quickly without scrolling through all of them. Therefore, a well-organized system is essential. With this dashboard, users can build course list easily and efficiently, enhancing their learning experience.
File: course-list.js
const courses = [
{ id: 1, name: "JavaScript Basics" },
{ id: 2, name: "HTML & CSS Fundamentals" },
{ id: 3, name: "Advanced JavaScript" },
];
function displayCourses(courses) {
const list = document.getElementById('course-list');
list.innerHTML = '';
courses.forEach(course => {
const item = document.createElement('li');
item.textContent = course.name;
list.appendChild(item);
});
}
displayCourses(courses);
function searchCourses(query) {
const filteredCourses = courses.filter(course => course.name.toLowerCase().includes(query.toLowerCase()));
displayCourses(filteredCourses);
}
// Usage example: search for "JavaScript"
searchCourses("JavaScript");
JavaScript Basics
HTML & CSS Fundamentals
Advanced JavaScript
The array courses holds all the available courses. The displayCourses function shows courses as a list on your web page. In addition, the searchCourses function filters these courses based on what the user types. It updates the displayed list with matching results. This method allows users to build course list dynamically according to their needs.
Your task is to add a search input box. It should allow users to filter courses in real-time as they type. This will enhance the user experience because students will find their desired courses instantly.
const input = document.getElementById('search-box');
input.addEventListener('input', () => {
searchCourses(input.value);
});
displayCourses function after filtering the courses, as it is crucial for displaying accurate results.toLowerCase() to ensure the search is not case-sensitive. This way, users can find their courses regardless of how they type.