forked from edwardbrowncross/cyf-homework-arrays-prototype
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHOMEWORK.js
93 lines (73 loc) · 2.26 KB
/
HOMEWORK.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function homework (renderList) {
// ❌ DO NOT CHANGE THE NAMES OF THE FUNCTIONS (eg. onAddTodo)
// DO NOT REMOVE renderList(todos); FROM THE END OF THE FUNCTIONS
// 👇 ONLY EDIT BELOW THIS LINE 👇
// The todos when you first load the page
let todos = [
'buy milk',
'go to gym',
'do CYF homework',
];
// ✅This function should:
// ◽ remove all of the todo items
function onClearAll () {
// Add code here
renderList(todos);
}
// ✅This function should:
// ◽ sort the array of todos alphabetically
function onSort () {
// Add code here
renderList(todos);
}
// ✅This function should:
// ◽ reverse the order of the todos in the array
function onReverse () {
// Add code here
renderList(todos);
}
// ✅This function should:
// ◽ add a new item to the end of the todos array
// ◽ bonus: do not allow new items to be less than 3 characters long
function onAddTodo (newTodoText) {
// Add code here
renderList(todos);
}
// ✅This function should:
// ◽ remove the item at the selected index
function onRemoveTodo (index) {
// Add code here
renderList(todos);
}
// ✅This function should:
// ◽ add a capital X to the start of the item ('buy milk' => 'X buy milk')
// ◽ bonus: don't add an X if it already has one (it's already complete)
// ◽ super bonus: remove the X if it already has one (put it back to incomplete)
function onCompleteTodo (index) {
// Add code here
renderList(todos);
}
// ✅This function should:
// ◽ remove from the list all of the completed items (that start with 'X')
function onRemoveCompleted () {
// Add code here
renderList(todos);
}
// ✅This function should:
// ◽ add an exclamation mark ('!') to the end of every item in the list
function onUrgent () {
// Add code here
renderList(todos);
}
// ✅This function should:
// ◽ display an alert with the first item on the list not marked as done (first without an 'X')
// ◽ bonus: consider what will happen if there are no more items left to do
function onWhatNext () {
alert('This is just a dummy message!');
}
// ☝ ONLY EDIT ABOVE THIS LINE ☝
renderList(todos);
return {
onAddTodo, onRemoveTodo, onCompleteTodo, onClearAll, onSort, onReverse, onRemoveCompleted, onUrgent, onWhatNext
};
}