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

// call pickFromArray with the quotes array to check you get a random quote

function displayRandomQuote() {
const randomQuote = pickFromArray(quotes);

document.getElementById("quote").textContent = randomQuote.quote;
document.getElementById("author").textContent = randomQuote.author;
}

// run when page loads2
displayRandomQuote();

// button click
document
.getElementById("new-quote")
.addEventListener("click", displayRandomQuote);
36 changes: 36 additions & 0 deletions Sprint-3/quote-generator/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,37 @@
/** Write your CSS in here **/
body {
font-family: Arial, sans-serif;
background-color: #f4f4f4;
text-align: center;
padding: 50px;
}

h1 {
color: #333;
}

#quote {
font-size: 1.5rem;
margin: 20px 0;
color: #222;
}

#author {
font-size: 1.2rem;
color: #666;
margin-bottom: 30px;
}

button {
padding: 10px 20px;
font-size: 1rem;
background-color: #007BFF;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
}

button:hover {
background-color: #0056b3;
}
2 changes: 2 additions & 0 deletions Sprint-3/todo-list/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ <h1>My ToDo List</h1>
<button id="add-task-btn">Add</button>
</div>

<button id="delete-completed-btn">Delete Completed</button>

<ul id="todo-list" class="todo-list">
</ul>

Expand Down
4 changes: 2 additions & 2 deletions Sprint-3/todo-list/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"type": "module",
"scripts": {
"serve": "http-server",
"test": "NODE_OPTIONS=--experimental-vm-modules jest"
"test": "set NODE_OPTIONS=--experimental-vm-modules && jest"
},
"repository": {
"type": "git",
Expand All @@ -20,4 +20,4 @@
"http-server": "^14.1.1",
"jest": "^30.0.4"
}
}
}
7 changes: 7 additions & 0 deletions Sprint-3/todo-list/script.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ const todos = [];
window.addEventListener("load", () => {
document.getElementById("add-task-btn").addEventListener("click", addNewTodo);

document
.getElementById("delete-completed-btn")
.addEventListener("click", () => {
Todos.deleteCompleted(todos);
render();
});

// Populate sample data
Todos.addTask(todos, "Wash the dishes", false);
Todos.addTask(todos, "Do the shopping", true);
Expand Down
23 changes: 23 additions & 0 deletions Sprint-3/todo-list/todos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Add a new task
export function addTask(todos, task, completed) {
todos.push({ task, completed });
}

// Delete a task by index
export function deleteTask(todos, index) {
if (index < 0 || index >= todos.length) return;
todos.splice(index, 1);
}

// Toggle completed status
export function toggleCompletedOnTask(todos, index) {
if (index < 0 || index >= todos.length) return;
todos[index].completed = !todos[index].completed;
}

// Delete all completed tasks
export function deleteCompleted(todos) {
const remaining = todos.filter((todo) => !todo.completed);
todos.length = 0;
todos.push(...remaining);
}
29 changes: 0 additions & 29 deletions Sprint-3/todo-list/todos.mjs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// npm test todos.test.mjs

// Import all the exported members through an object
import * as Todos from "./todos.mjs";
import * as Todos from "./todos.js";

// Return a mock ToDo List data with exactly 4 elements.
function createMockTodos() {
Expand Down Expand Up @@ -130,3 +130,40 @@ describe("toggleCompletedOnTask()", () => {
});
});

describe("deleteCompleted()", () => {
test("removes all completed tasks from the list", () => {
const todos = createMockTodos();

Todos.deleteCompleted(todos);

expect(todos).toEqual([
{ task: "Task 2 description", completed: false },
{ task: "Task 4 description", completed: false },
]);
});

test("does nothing if no tasks are completed", () => {
const todos = [
{ task: "Task A", completed: false },
{ task: "Task B", completed: false },
];

Todos.deleteCompleted(todos);

expect(todos).toEqual([
{ task: "Task A", completed: false },
{ task: "Task B", completed: false },
]);
});

test("removes all tasks if all are completed", () => {
const todos = [
{ task: "Task A", completed: true },
{ task: "Task B", completed: true },
];

Todos.deleteCompleted(todos);

expect(todos).toEqual([]);
});
});
Loading