Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Sprint-3/slideshow/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<title>Image carousel</title>
<script defer src="slideshow.js"></script>
</head>
<body>
<img id="carousel-img" src="./assets/cute-cat-a.png" alt="cat-pic" />
<button type="button" id="backward-btn">Backwards</button>
<button type="button" id="forward-btn">Forward</button>

<button type="button" id="auto-forward">Auto Forward</button>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work! @Baba05206

<button type="button" id="auto-backward">Auto Backward</button>
<button type="button" id="stop">Stop</button>
</body>
</html>
61 changes: 57 additions & 4 deletions Sprint-3/slideshow/slideshow.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,61 @@
const images = [
"./assets/cute-cat-a.png",
"./assets/cute-cat-b.jpg",
"./assets/cute-cat-c.jpg",
"./assets/cute-cat-a.png",
"./assets/cute-cat-b.jpg",
"./assets/cute-cat-c.jpg",
Copy link

@jaymes15 jaymes15 Dec 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good use of array to store image paths.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add one more image path to the images array.
(the instructions say “at least 4”)

];

//Write your code here
let currentIndex = 0;
let intervalId = null;

// Write your code here
const imgElement = document.getElementById("carousel-img");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct DOM selection

const forwardBtn = document.getElementById("forward-btn");
const backwardBtn = document.getElementById("backward-btn");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clear variable names


const autoForwardBtn = document.getElementById("auto-forward");
const autoBackwardBtn = document.getElementById("auto-backward");
const stopBtn = document.getElementById("stop");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of const because they don’t change


function updateImage() {
imgElement.src = images[currentIndex];
}

function moveForward() {
currentIndex = (currentIndex + 1) % images.length;
updateImage();
}

function moveBackward() {
currentIndex = (currentIndex - 1 + images.length) % images.length;
updateImage();
}

forwardBtn.addEventListener("click", moveForward);
backwardBtn.addEventListener("click", moveBackward);

// ---- AUTOMATIC SLIDESHOW ----

function startAuto(direction) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥very good job wiith this function

stopAuto(); // clear any previous interval

// Disable auto buttons
autoForwardBtn.disabled = true;
autoBackwardBtn.disabled = true;

intervalId = setInterval(() => {
direction === "forward" ? moveForward() : moveBackward();
}, 2000);
}

function stopAuto() {
clearInterval(intervalId);
intervalId = null;

// Re-enable buttons
autoForwardBtn.disabled = false;
autoBackwardBtn.disabled = false;
}

autoForwardBtn.addEventListener("click", () => startAuto("forward"));
autoBackwardBtn.addEventListener("click", () => startAuto("backward"));
stopBtn.addEventListener("click", stopAuto);