-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (44 loc) · 1.54 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Initialise an empty object to store the TODO list items.
let todoList = {};
/**
* Adds a new TODO item to the list.
* @param {string} key - The unique identifier for the TODO item.
* @param {string} value - The description of the TODO item.
*/
function addTodo(key, value) {
// Assign the value to the key in the todoList object.
// This creates a new key-value pair if the key doesn't exist,
// or updates the value if the key already exists.
todoList[key] = value;
}
/**
* Updates the description of an existing TODO item.
* @param {string} key - The unique identifier for the TODO item to update.
* @param {string} newValue - The new description for the TODO item.
*/
function updateTodo(key, newValue) {
// Check if the TODO item exists in the list by its key.
if (todoList[key]) {
// Update the value associated with the key to the new value.
todoList[key] = newValue;
}
}
/**
* Deletes a TODO item from the list.
* @param {string} key - The unique identifier for the TODO item to delete.
*/
function deleteTodo(key) {
// Use the delete operator to remove the key-value pair from the todoList object.
delete todoList[key];
}
/**
* Marks a TODO item as completed by appending '(Completed)' to its description.
* @param {string} key - The unique identifier for the TODO item to mark as complete.
*/
function markComplete(key) {
// Check if the TODO item exists in the list by its key.
if (todoList[key]) {
// Append the string ' (Completed)' to the existing value of the TODO item.
todoList[key] += ' (Completed)';
}
}