Skip to content

ITP-JAN-LONDON|FOROGH AGHAEIYARIJANI|MODULE-DATA-GROUP|SPRINT3|SLIDESHOW APP|Image carousel #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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: 3 additions & 3 deletions Sprint-2/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Sprint-3/slideshow/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<title>Image carousel</title>
<link rel="stylesheet" href="styles.css" />
<script defer src="slideshow.js"></script>
</head>
<body>
<img id="carousel-img" src="./assets/cute-cat-a.png" alt="cat-pic" />
<p id="image-counter">Image 1 of 4</p>

<button type="button" id="backward-btn">Backwards</button>
<button type="button" id="forward-btn">Forward</button>
</body>
Expand Down
81 changes: 77 additions & 4 deletions Sprint-3/slideshow/slideshow.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,81 @@
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",
"./assets/cute-cat-d.jpg",
];

let currentIndex = 0;
let intervalId = null;

// Write your code here
const imgElement = document.getElementById("carousel-img");
const forwardBtn = document.getElementById("forward-btn");
const backwardBtn = document.getElementById("backward-btn");
const imageCounter = document.getElementById("image-counter");

const autoForwardBtn = document.createElement("button");
const autoBackwardBtn = document.createElement("button");
const stopBtn = document.createElement("button");

autoForwardBtn.textContent = "Auto Forward";
autoBackwardBtn.textContent = "Auto Backward";
stopBtn.textContent = "Stop";

autoForwardBtn.id = "auto-forward";
autoBackwardBtn.id = "auto-backward";
stopBtn.id = "stop";

document.body.appendChild(autoForwardBtn);
document.body.appendChild(autoBackwardBtn);
document.body.appendChild(stopBtn);
Comment on lines +20 to +30
Copy link

Choose a reason for hiding this comment

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

Why not just add these as HTML elements in index.html?

Choose a reason for hiding this comment

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

I did it.


function updateImage(index) {
imgElement.src = images[index];
imageCounter.textContent = `Image ${index + 1} of ${images.length}`;
}

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

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

function startAutoForward() {
stopSlideshow();
intervalId = setInterval(moveForward, 2000);
disableButtons();
}

function startAutoBackward() {
stopSlideshow();
intervalId = setInterval(moveBackward, 2000);
disableButtons();
}

function stopSlideshow() {
clearInterval(intervalId);
enableButtons();
}

function disableButtons() {
autoForwardBtn.disabled = true;
autoBackwardBtn.disabled = true;
}

function enableButtons() {
autoForwardBtn.disabled = false;
autoBackwardBtn.disabled = false;
}

forwardBtn.addEventListener("click", moveForward);
backwardBtn.addEventListener("click", moveBackward);
autoForwardBtn.addEventListener("click", startAutoForward);
autoBackwardBtn.addEventListener("click", startAutoBackward);
stopBtn.addEventListener("click", stopSlideshow);


updateImage(currentIndex);
17 changes: 17 additions & 0 deletions Sprint-3/slideshow/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,18 @@
/** Write your CSS in here **/
#carousel-img {
width: 500px;
height: 400px;
object-fit: cover;
display: block;
margin-bottom: 10px;
}

button {
margin: 5px;
}

#image-counter {
margin-bottom: 10px;
font-weight: bold;
}

24 changes: 24 additions & 0 deletions prep sprint3/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<script defer src="script.js"></script>
</head>
<body>
<section>
<h3>Character limit</h3>
<label for="comment-input">
Please enter your comment in the text area below
</label>
<textarea
id="comment-input"
name="comment-input"
rows="5"
maxlength="200"
></textarea>
<p id="character-limit-info">You have 200 characters remaining</p>
</section>
</body>
</html>
5 changes: 5 additions & 0 deletions prep sprint3/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const textarea = document.querySelector("textarea");
console.log(textarea.value); // evaluates to the value typed by the user

const limitDisplay = document.querySelector("#character-limit-info");
limitDisplay.innerText = "You have loaded the page.";