Tell us what’s happening:
I’ve been stuck on this particular workshop for days right now, the following test cases have been failing non-stop no matter what I try:
- Failed:13. The
MotorcycleGalleryAppshould have an array namedallMotorcycles. - Failed:17. The
renderMotorcyclesfunction should render 25 elements with a class ofmotorcycle-card-image-container. - Failed:18. The
renderMotorcyclesfunction should render 25 elements with a class ofmotorcycle-card-year-badge. - Failed:19. The
renderMotorcyclesfunction should render 25 elements with a class ofmotorcycle-card-title. - Failed:20. The
renderMotorcyclesfunction should render 25 elements with a class ofmotorcycle-card-manufacturer. - Failed:21. The
renderMotorcyclesfunction should render 25 elements with a class ofmotorcycle-card-category. - Failed:22. The
renderMotorcyclesfunction should render 25 elements with a class ofmotorcycle-card-description. - Failed:23. The
renderMotorcyclesfunction should render 25 elements with a class ofmotorcycle-card-price. - Failed:24. The
renderMotorcyclesfunction should render 25 elements with a class ofmotorcycle-card-engine.
I can see the the function, successfully render all 25 elements in the preview, I’ve also ensured that the following class names are also present, any help would be appreciated.
Your code so far
type Category = 'Sport' | 'Cruiser' | 'Touring' | 'Dirt' | 'Adventure' | 'Naked' | 'Electric';
interface Motorcycle {
id: string;
name: string;
manufacturer: string;
category: Category;
price: number;
image_url: string;
created_at: Date;
description: string;
year: number;
engine?: string | number;
}
async function fetchMotorcycles(): Promise<Motorcycle[]> {
const response = await fetch('https://cdn.freecodecamp.org/curriculum/labs/data/motorcycles.json');
return response.json();
}
function renderMotorcycleCard(motorcycle: Motorcycle): string {
return `
<div class="motorcycle-card">
<div class="motorcycle-card-image-container">
<img src="${motorcycle.image_url}" alt="${motorcycle.name}" class="motorcycle-card-image">
<div class="motorcycle-card-year-badge">
${motorcycle.year}
</div>
</div>
<div class="motorcycle-card-content">
<div class="motorcycle-card-header">
<div>
<h3 class="motorcycle-card-title">${motorcycle.name}</h3>
<p class="motorcycle-card-manufacturer">${motorcycle.manufacturer}</p>
</div>
<span class="motorcycle-card-category">
${motorcycle.category}
</span>
</div>
<p class="motorcycle-card-description">${motorcycle.description}</p>
<div class="motorcycle-card-footer">
<div>
<p class="motorcycle-card-price">
$${motorcycle.price}
</p>
<p class="motorcycle-card-engine">${motorcycle.engine}</p>
</div>
<button class="motorcycle-card-button" data-motorcycle-id="${motorcycle.id}">
View Details
</button>
</div>
</div>
</div>
`;
}
class MotorcycleGalleryApp {
private allMotorcycles: Motorcycle[];
constructor(motorcycles: Motorcycle[]) {
this.allMotorcycles = motorcycles;
}
renderMotorcycles(): void {
const grid = document.getElementById('motorcycle-grid');
const resultsNumber = document.getElementById('results-number');
if (grid) {
grid.innerHTML = this.allMotorcycles.map(renderMotorcycleCard).join('');
}
if (resultsNumber) {
resultsNumber.textContent = this.allMotorcycles.length.toString();
}
}
}
fetchMotorcycles().then(motorcycles => {
const app = new MotorcycleGalleryApp(motorcycles);
app.renderMotorcycles();
const filterInput = document.getElementById('name-filter-input');
if (filterInput) {
filterInput.addEventListener('input', (e: Event) => {
const searchTerm = (e.target as HTMLInputElement).value.toLowerCase();
const filteredMotorcycles = motorcycles.filter(motorcycle =>
motorcycle.name.toLowerCase().includes(searchTerm)
);
const grid = document.getElementById('motorcycle-grid');
const resultsNumber = document.getElementById('results-number');
if (grid) {
grid.innerHTML = filteredMotorcycles.map(renderMotorcycleCard).join('');
}
if (resultsNumber) {
resultsNumber.textContent = filteredMotorcycles.length.toString();
}
});
}
});
Lesson URL (copy - paste from your browser’s address bar):