Image Carousel in JavaScript

Create an image carousel

BeginnerMini ProjectsExample 7 of 20
image-carousel.js
1class Carousel {
2 constructor(images) { this.images = images; this.current = 0; }
3 next() { this.current = (this.current + 1) % this.images.length; }
4 prev() { this.current = (this.current - 1 + this.images.length) % this.images.length; }
5 getCurrent() { return this.images[this.current]; }
6}

Output

// Carousel functionality

What's going on

Image Carousel displays images in rotation.