Published on January 26, 2024By DeveloperBreeze

// Initialize the current index
let currentIndex = 0;

// Array of image file names
const images = ['image1.jpg', 'image2.jpg', 'image3.jpg'];

// Function to display the current image
function showImage(index) {
    console.log('Displaying Image:', images[index]);
}

// Function to display the next image
function nextImage() {
    currentIndex = (currentIndex + 1) % images.length;
    showImage(currentIndex);
}

// Function to display the previous image
function prevImage() {
    currentIndex = (currentIndex - 1 + images.length) % images.length;
    showImage(currentIndex);
}

// Show the initial image
showImage(currentIndex);

Comments

Please log in to leave a comment.

Continue Reading:

Reversing a String in JavaScript: A Simple Guide

Published on January 26, 2024

javascriptpython

Batch File Renaming Using os Module

Published on January 26, 2024

python

JavaScript Display To-Do List

Published on January 26, 2024

javascript

JavaScript Check if Array Contains Element

Published on January 26, 2024

javascript

JavaScript Remove Duplicates from an Array

Published on January 26, 2024

javascript

JavaScript Sum of Array Elements

Published on January 26, 2024

javascript

Sorting an Array

Published on January 26, 2024

javascript

Sorting an Array in JavaScript

Published on January 26, 2024

javascript

Optimizing Large Database Queries in Laravel

Published on November 16, 2024

php