Frontend School

Interactive Image Carousel

Machine Coding
medium

Interactive Image Carousel

Medium
React
Frontend
UI
State Management
Event Handling

Overview

In modern web applications, displaying a collection of images in an engaging and efficient manner is crucial for user experience. Whether it's a product gallery on an e-commerce site, a portfolio showcase, or a photo album in a social media app, an interactive image carousel is a fundamental UI component. This problem challenges you to build a functional and intuitive image carousel, similar to those found across Meta's various platforms, focusing on core state management and user interaction.

What you need to do / Task

Your primary goal is to build a React component that displays a series of images in a carousel format. Specifically, you must:

  1. Display a Single Image: Render only one image from a given list at a time within the carousel viewport.
  2. Implement Navigation Buttons: Add "Previous" and "Next" buttons to allow users to cycle through the images.
  3. Handle Wrap-Around Logic: Ensure that navigating "Next" from the last image goes to the first image, and navigating "Previous" from the first image goes to the last image.
  4. Implement Dot Indicators: Display a set of clickable dot indicators, one for each image. The dot corresponding to the currently displayed image should be visually distinct (e.g., highlighted).
  5. Direct Navigation via Dots: Clicking on a dot indicator should immediately navigate the carousel to the corresponding image.

UI/UX expectations

  • The main image should be centrally displayed.
  • "Previous" and "Next" buttons should be clearly visible and positioned to the left and right of the main image, respectively.
  • Dot indicators should be arranged horizontally, typically below the main image.
  • The active dot indicator should have a distinct visual style (e.g., different background color, border, or size).
  • Basic styling should be applied to make the carousel functional and presentable. Focus on clarity and interaction rather than pixel-perfect design.

Acceptance criteria

  • Only one image is visible in the main display area at any given time.
  • Clicking the "Next" button advances the carousel to the subsequent image. If at the last image, it cycles to the first.
  • Clicking the "Previous" button moves the carousel to the prior image. If at the first image, it cycles to the last.
  • The correct dot indicator is visually highlighted to reflect the currently displayed image.
  • Clicking any dot indicator updates the main image display to show the image corresponding to that dot.
  • The component should be reusable with different sets of image data.

Constraints

Constraints & assumptions

  • You must use React for building the component.
  • The image data will be provided as an array of objects, each containing an id, src (URL), and alt text.
  • You are expected to build the carousel logic from scratch; do not use external carousel libraries (e.g., react-slick, swiper).
  • Focus on functional correctness and clean component structure. Responsiveness is a secondary concern.
  • Assume image URLs are valid and will load successfully.
  • The time budget for this problem is approximately 45 minutes.

Out of scope (optional)

  • Automatic image transitions (auto-play).
  • Keyboard navigation (e.g., arrow keys).
  • Complex animations or transitions between images (basic CSS transitions are acceptable if time permits, but not required).
  • Error handling for broken image links.
  • Accessibility beyond basic button/indicator roles (e.g., aria-label for buttons is good practice but not strictly required for L3 core).

What interviewers evaluate

  • Correctness and Robustness: Does the carousel function as expected under all specified conditions, including edge cases (first/last image)?
  • React Fundamentals: Proper use of state, props, and component lifecycle for managing UI and interactions.
  • Component Design: Is the component well-structured, modular, and easy to understand? Are concerns separated appropriately?
  • Code Quality: Readability, maintainability, and adherence to good coding practices.
  • UI/UX Implementation: Basic visual presentation and intuitive user interactions.

Loading editor...