Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
bc8ae20
Created file mean.js & test file mean.test.js and wrote code and test…
EL1VAS Nov 6, 2025
5c7adf7
Created files for exercises and their tests. Copied the code.
EL1VAS Nov 6, 2025
c27dca3
Copied the code in exercise-2 file
EL1VAS Nov 6, 2025
d67bad2
Defined the variable as an array
EL1VAS Nov 6, 2025
b610439
Made numbers the parameter
EL1VAS Nov 6, 2025
67bc3d1
Tried to log the doubleAllNumbers (and failed)
EL1VAS Nov 6, 2025
98a84fc
Created a variable that i could log in the console
EL1VAS Nov 6, 2025
0d09f79
Wrote the function to swap first-last digits of array
EL1VAS Nov 6, 2025
4a38ce9
Deleted the arr[] as testing indicated it was already declared
EL1VAS Nov 6, 2025
526f252
changed title
EL1VAS Nov 24, 2025
19f1813
Wrote the function to detect index and move forward or backwards. Add…
EL1VAS Nov 24, 2025
add3148
removed <img> from title
EL1VAS Nov 24, 2025
b65c360
Adding things to pass the test
EL1VAS Nov 24, 2025
efb9277
Trying to pass the test, live server working tests failing
EL1VAS Nov 24, 2025
60c45ed
Typos
EL1VAS Nov 24, 2025
4f6e982
Added comments
EL1VAS Nov 25, 2025
ddcf9a9
Added the buttons of auto forward, auto backward and stop
EL1VAS Nov 25, 2025
85d7cb1
Created the functions for auto slideshow and stop. Enabled/disabled t…
EL1VAS Nov 25, 2025
583e04b
Try to arrange all imgs to have the same size as the first and added …
EL1VAS Nov 25, 2025
eb97016
Added all buttons in a div for css manipulation
EL1VAS Nov 25, 2025
33254a2
Styling the buttons
EL1VAS Nov 25, 2025
ba68494
Added class to buttons for css manipulation
EL1VAS Nov 25, 2025
d4224ca
Styling buttons and fixed typo
EL1VAS Nov 25, 2025
547d595
Styling buttons and body
EL1VAS Nov 25, 2025
bf5394b
Styling buttons and body
EL1VAS Nov 25, 2025
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
2 changes: 1 addition & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"requirePragma": false,
"semi": true,
"singleQuote": false,
"tabWidth": 2,
"tabWidth": 4,
"trailingComma": "es5",
"useTabs": false,
"vueIndentScriptAndStyle": false
Expand Down
36 changes: 25 additions & 11 deletions Sprint-3/slideshow/index.html
Original file line number Diff line number Diff line change
@@ -1,14 +1,28 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</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>
</body>
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Image carousel</title>
<script defer src="slideshow.js"></script>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<img id="carousel-img" src="./assets/cute-cat-a.png" alt="cat-pic" />
<div id="button-container">
<button type="button" class="button" id="auto-backward">
Auto Backward
</button>
<button type="button" class="button" id="backward-btn">
Backwards
</button>
<button type="button" class="button" id="stop">Stop</button>
<button type="button" class="button" id="forward-btn">
Forward
</button>
<button type="button" class="button" id="auto-forward">
Auto Forward
</button>
</div>
</body>
</html>
10 changes: 5 additions & 5 deletions Sprint-3/slideshow/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,18 @@ Make your buttons work to navigate forwards and backwards, manually.

Add the following buttons:

- auto-forward
- stop
- auto-backwards
- auto-forward
- stop
- auto-backwards

These should allow automatic navigation through the images, say every 5 seconds.

### End of basic challenge!

Congratulations, you've finished the basics!

- Make sure you can access it and play with it on a smartphone!
- Celebrate!
- Make sure you can access it and play with it on a smartphone!
- Celebrate!

## Further work

Expand Down
71 changes: 69 additions & 2 deletions Sprint-3/slideshow/slideshow.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,75 @@
const images = [
window.images = [
"./assets/cute-cat-a.png",
"./assets/cute-cat-b.jpg",
"./assets/cute-cat-c.jpg",
];

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

// Write your code here
// Manual movement of carousel
function moveFrontOnce(forward) {
const images = window.images;
console.log("moveFrontOnce called, forward = ", forward); // Trying to troubleshoot
if (forward === true) {
currentIndex = (currentIndex + 1) % images.length; // If forward is true adds 1 to the index
// and wraps with % images.length in case we are in the last index
} else {
currentIndex = (currentIndex - 1 + images.length) % images.length; // Same here if backward it deducts one index
//making sure it wraps back to last image in case we were at index[0]
}
const image = document.getElementById("carousel-img");
image.setAttribute("src", images[currentIndex]); // Changed the approach while trying to pass the tests
console.log("Image src is set to:", image.src); // Tests shows that my img src is undefined
}

// Auto movement of carousel forward
function startAutoForward() {
stopAuto(); // Function to stop the autoslide before we start
intervalId = setInterval(() => moveFrontOnce(true), 2000); // Starts the autoslide forward every 2"
toggleButtons(true); // Auto-forward button active
}

// Auto movement of carousel backwards
function startAutoBackward() {
stopAuto(); // Stop the autoslide before we start
intervalId = setInterval(() => moveFrontOnce(false), 2000); // Starts the autoslide backwards
toggleButtons(true); // Auto-backward button active
}

// Stops automatic slideshow
function stopAuto() {
if (intervalId !== null) {
clearInterval(intervalId);
intervalId = null;
}
toggleButtons(false);
}

// Enables/disables buttons based on if autoslideshow is running
function toggleButtons(isRunning) {
document.getElementById("auto-forward").disabled = isRunning; // When the auto slideshow is on auto-forward button is unclickable
document.getElementById("auto-backward").disabled = isRunning; // When auto slideshow is on auto-backward button is unclicable
document.getElementById("stop").disabled = !isRunning; // Stop button is disabled only when auto slideshow is off, so when autoslideshow is running
//stop is the only button we can click
}

// Activate (call) the buttons
document.addEventListener("DOMContentLoaded", () => {
document
.getElementById("forward-btn")
.addEventListener("click", () => moveFrontOnce(true));
document
.getElementById("backward-btn")
.addEventListener("click", () => moveFrontOnce(false));
document
.getElementById("auto-forward")
.addEventListener("click", () => startAutoForward());
document
.getElementById("auto-backward")
.addEventListener("click", () => startAutoBackward());
document.getElementById("stop").addEventListener("click", () => stopAuto());
// Disable stop button initially when autoslideshow is not running yet
document.getElementById("stop").disabled = true;
});
27 changes: 27 additions & 0 deletions Sprint-3/slideshow/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,28 @@
/** Write your CSS in here **/
body {
background-color: rgb(242, 106, 106);
}
#carousel-img {
width: 745px;
height: 559px;
object-fit: cover; /* ensures the image covers the area without distortion */
display: block; /* removes any inline whitespace below image */
margin: 0 auto; /* center horizontally if needed */
}

#button-container {
display: flex;
justify-content: center; /* Justify in horizontal axis*/
gap: 10px;
margin-top: 20px;
}

.button {
background-color: bisque;
font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif
font-size: Verdana, Geneva, Tahoma, sans-serif
font-style: oblique;
border-radius: 8px;
padding: 10px 20px;
cursor: pointer;
}
14 changes: 14 additions & 0 deletions prep/exercise-1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Can you fix this code?
function doubleAllNumbers(numbers) {
let doubledNumbers = [];

for (let n of numbers) {
doubledNumbers.push(n * 2);
}

return doubledNumbers;
}

const myNums = [10, 20, 30];
const double = doubleAllNumbers(myNums);
console.log(double);
Empty file added prep/exercise-1.test.js
Empty file.
13 changes: 13 additions & 0 deletions prep/exercise-2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Write a function which takes an array as a parameter
// and swaps the first element with the last element

function swapFirstAndLast(arr) {
const first = arr[0]; //Indivates the first digit location of the array
const last = arr[arr.length - 1]; //Indicates the lst digit location of the array
arr[0] = last; //Because I can't reassign a new value to a const and we want the first position to hold the value of the last
arr[arr.length - 1] = first;
}

const myArray = [5, 2, 3, 4, 1];
swapFirstAndLast(myArray);
console.log(myArray); // what output should we expect?
Empty file added prep/exercise-2.test.js
Empty file.
20 changes: 20 additions & 0 deletions prep/mean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
function calculateMean(list) {
let total = 0;
for (const item of list) {
total += item;
}
}

function calculateMedian(list) {
const middleIndex = Math.floor(list.length / 2);
const median = list.splice(middleIndex, 1)[0];

return median;
}

const list = [10, 20, 30];
const copy = list;
copy.push(60, 70);

console.log(list);
console.log(copy);
6 changes: 6 additions & 0 deletions prep/mean.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
test("calculates the median of a list of odd length", () => {
const list = [10, 20, 30, 50, 60];
const currentOutput = calculateMedian(list);
const targetOutput = 30;
expect(currentOutput).toEqual(targetOutput);
});