Skip to content

Glasgow| 25-ITP-May | Bassam Alshujaa | Sprint 3 | Data-Groups #703

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 6 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
30 changes: 29 additions & 1 deletion Sprint-3/alarmclock/alarmclock.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,32 @@
function setAlarm() {}
let countInterval;
function setAlarm() {
clearInterval(countInterval);
const timeInput = document.getElementById("alarmSet"); // now matches the HTML
const seconds = parseInt(timeInput.value, 10);

if (isNaN(seconds) || seconds <= 0) {
alert("Please enter a valid number of seconds.");
return;
}
let remainingSeconds = seconds;

countInterval = setInterval(() => {
if (remainingSeconds <= 0) {
clearInterval(showTime);
playAlarm();
return;
}

remainingSeconds--;

const mins = String(Math.floor(remainingSeconds / 60)).padStart(2, "0");
const secs = String(remainingSeconds % 60).padStart(2, "0");

document.getElementById(
"timeRemaining"
).innerText = `Time Remaining: ${mins}:${secs}`;
}, 1000);
}

// DO NOT EDIT BELOW HERE

Expand Down
1 change: 1 addition & 0 deletions Sprint-3/quote-generator/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css">
<title>Title here</title>
<script defer src="quotes.js"></script>
</head>
Expand Down
18 changes: 18 additions & 0 deletions Sprint-3/quote-generator/quotes.js
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,21 @@ const quotes = [
];

// call pickFromArray with the quotes array to check you get a random quote
function showRandomQuote() {
const randomQuote = pickFromArray(quotes);
const quoteElement = document.getElementById("quote");
const authorElement = document.getElementById("author");

quoteElement.textContent = `"${randomQuote.quote}"`;
authorElement.textContent = ` ${randomQuote.author}`;
}

function setup() {
const button = document.getElementById("new-quote");
button.addEventListener("click", showRandomQuote);

// Show one quote immediately on page load
showRandomQuote();
}

window.addEventListener("DOMContentLoaded", setup);
64 changes: 64 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,65 @@
/** Write your CSS in here **/
/* Reset some default styles */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background: linear-gradient(to right, #74ebd5, #acb6e5);
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
padding: 20px;
gap: 10px;
}

.quote-container {
background: #ffffff;
padding: 30px 40px;
border-radius: 12px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
max-width: 600px;
text-align: center;
}

h1 {
margin-bottom: 20px;
font-size: 2rem;
color: #333;
}

#quote {
font-size: 1.5rem;
font-style: italic;
color: #555;
margin-bottom: 10px;
}

#author {
font-size: 1.1rem;
color: #05074a;
border-bottom: solid 2px #05074a;
margin-bottom: 20px;
font-weight: bold;
}

#new-quote {
padding: 10px 20px;
font-size: 1rem;
border: none;
border-radius: 8px;
background-color: #5c6bc0;
color: white;
cursor: pointer;
transition: background-color 0.3s ease;
}

#new-quote:hover {
background-color: #05074a;
color: white;
}
17 changes: 17 additions & 0 deletions Sprint-3/reading-list/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ const books = [
},
];

const readingList = document.getElementById("reading-list");

books.forEach((book) => {
const li = document.createElement("li");

li.style.backgroundColor = book.alreadyRead ? "green" : "red";

const text = document.createElement("p");
text.innerText = `${book.title} by ${book.author}`;
li.appendChild(text);

const img = document.createElement("img");
img.src = book.bookCoverImage;
li.appendChild(img);

readingList.appendChild(li);
});
1 change: 1 addition & 0 deletions Sprint-3/slideshow/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css">
<title>Title here</title>
<script defer src="slideshow.js"></script>
</head>
Expand Down
29 changes: 25 additions & 4 deletions Sprint-3/slideshow/slideshow.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
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",
];

// Write your code here
let currentIndex = 0;

// Write your code here
// Get references to DOM elements
const imgElement = document.getElementById("carousel-img");
const forwardButton = document.getElementById("forward-btn");
const backwardButton = document.getElementById("backward-btn");

// Function to update the image src
function updateImage() {
imgElement.src = images[currentIndex];
}

// Event listeners for buttons
forwardButton.addEventListener("click", () => {
currentIndex = (currentIndex + 1) % images.length;
updateImage();
});

backwardButton.addEventListener("click", () => {
currentIndex = (currentIndex - 1 + images.length) % images.length;
updateImage();
});
41 changes: 40 additions & 1 deletion Sprint-3/slideshow/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
/** Write your CSS in here **/
/* Center everything on the page */
body {
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
min-height: 100vh;
margin: 0;
font-family: Arial, sans-serif;
background-color: #f5f5f5;
gap: 20px;
}
img{
width: 60%;
}
#carousel-img {
max-width: 90%;
height: auto;
border: 4px solid #ccc;
border-radius: 10px;
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
margin-bottom: 20px;
}

button {
padding: 10px 20px;
margin: 0 10px;
font-size: 16px;
font-weight: bold;
color: #fff;
background-color: #3498db;
border: none;
border-radius: 6px;
cursor: pointer;
transition: background-color 0.3s ease;
}

button:hover {
background-color: #2980b9;
}
2 changes: 2 additions & 0 deletions Sprint-3/todo-list/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Title here</title>
<link rel="stylesheet" href="style.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" />
</head>
<body>
<form>
Expand All @@ -22,6 +23,7 @@
</button>
</div>
</form>
<ul id="todo-list"></ul>
<script src="script.js"></script>
</body>
</html>
56 changes: 48 additions & 8 deletions Sprint-3/todo-list/script.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,65 @@
function populateTodoList(todos) {
let list = document.getElementById("todo-list");
// Write your code to create todo list elements with completed and delete buttons here, all todos should display inside the "todo-list" element.
list.innerHTML = "";

Choose a reason for hiding this comment

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

Remember what the readme file asks for - you need a button that can toggle the completed state of the task. Without this, it's not possible to fully test this.


todos.forEach((todo, index) => {
const li = document.createElement("li");
li.innerText = todo.task;

if (todo.completed) {
li.style.textDecoration = "line-through";
}

const span = document.createElement("span");

const checkBtn = document.createElement("i");
checkBtn.className = "fa fa-check mx-1";
checkBtn.style.cursor = "pointer";
checkBtn.addEventListener("click", () => {
todo.completed = !todo.completed;
li.style.textDecoration = todo.completed ? "line-through" : "none";
});

const trashBtn = document.createElement("i");
trashBtn.className = "fa fa-trash mx-1";
trashBtn.style.cursor = "pointer";
trashBtn.addEventListener("click", () => {
todos.splice(index, 1);
populateTodoList(todos);
});

span.appendChild(checkBtn);
span.appendChild(trashBtn);
li.appendChild(span);
list.appendChild(li);
});
}

// These are the same todos that currently display in the HTML
// You will want to remove the ones in the current HTML after you have created them using JavaScript
let todos = [
{ task: "Wash the dishes", completed: false },
{ task: "Do the shopping", completed: false },
];

populateTodoList(todos);

// This function will take the value of the input field and add it as a new todo to the bottom of the todo list. These new todos will need the completed and delete buttons adding like normal.
function addNewTodo(event) {
// The code below prevents the page from refreshing when we click the 'Add Todo' button.
event.preventDefault();
// Write your code here... and remember to reset the input field to be blank after creating a todo!
const input = document.querySelector("input");
const newTask = input.value.trim();
if (newTask !== "") {
todos.push({ task: newTask, completed: false });
populateTodoList(todos);
input.value = "";
}
}

// Advanced challenge: Write a fucntion that checks the todos in the todo list and deletes the completed ones (we can check which ones are completed by seeing if they have the line-through styling applied or not).
document.querySelector("form").addEventListener("submit", addNewTodo);

function deleteAllCompletedTodos() {
// Write your code here...
todos = todos.filter((todo) => !todo.completed);
populateTodoList(todos);
}

document
.getElementById("remove-all-completed")
.addEventListener("click", deleteAllCompletedTodos);
Loading