Challenge - 5 Problems
Carousel Control Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediateHow to programmatically move to the next slide in a Bootstrap carousel?
You have a Bootstrap carousel with the ID
#myCarousel. Which JavaScript code snippet correctly moves the carousel to the next slide?Attempts:
2 left
💡 Hint
Remember to create a Carousel instance with the element before calling methods.
✗ Incorrect
In Bootstrap 5, you create a Carousel instance by passing the DOM element to the constructor. Then you call the
next() method to move to the next slide. Option D does this correctly. Option D uses jQuery style which is not valid. Option D tries to get an instance from a selector string instead of an element. Option D uses a wrong method name slide.📝 Syntax
intermediateIdentify the syntax error in this Bootstrap carousel control code
What error will this code produce?
var carousel = new bootstrap.Carousel(document.querySelector('#carouselExample')); carousel.to(2);Attempts:
2 left
💡 Hint
Check if
to() is a valid method of Bootstrap Carousel instance.✗ Incorrect
The
to(index) method is valid in Bootstrap 5 Carousel API and moves the carousel to the slide at the given zero-based index. So this code runs without error and moves to slide 2 (the third slide).❓ rendering
advancedWhat will be the visible slide after running this code?
Given a Bootstrap carousel with 4 slides (indexes 0 to 3), what slide will be visible after this code?
var carousel = new bootstrap.Carousel(document.querySelector('#myCarousel')); carousel.to(5);Attempts:
2 left
💡 Hint
Check how Bootstrap handles out-of-range slide indexes.
✗ Incorrect
Bootstrap Carousel clamps the slide index to the last slide if the index is greater than the number of slides. So calling
to(5) on a 4-slide carousel moves to the last slide (index 3).❓ selector
advancedWhich selector correctly targets the active slide in a Bootstrap carousel?
You want to select the currently visible slide inside a Bootstrap carousel with ID
#exampleCarousel. Which CSS selector will select the active slide?Attempts:
2 left
💡 Hint
Bootstrap marks the visible slide with a specific class.
✗ Incorrect
Bootstrap adds the class
active to the currently visible slide inside the carousel. So the selector #exampleCarousel .carousel-item.active correctly targets the active slide within that carousel. Option B uses a class show which is not used for slides. Option B selects active slides globally, not scoped to the carousel. Option B uses a non-existent class.❓ accessibility
expertHow to improve keyboard accessibility for Bootstrap carousel controls?
Which practice best improves keyboard accessibility for the next and previous buttons in a Bootstrap carousel?
Attempts:
2 left
💡 Hint
Think about how keyboard users and screen readers interact with controls.
✗ Incorrect
Adding
tabindex="0" makes the buttons focusable by keyboard. Adding descriptive aria-label helps screen reader users understand the button's purpose. Option A misses keyboard focus. Option A hides controls from assistive tech, which is bad. Option A removes manual control, hurting accessibility.