Skip to content

Commit 4b96415

Browse files
committed
#25 - JavaScript
1 parent 72d0b61 commit 4b96415

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
console.log("This is a general message");
2+
console.info("This is an infomational message");
3+
console.warn("Warning: This is a warning message");
4+
console.error("Error: This is an error message");
5+
console.debug("Debug: This is a debug message");
6+
7+
// Extra Exercise //
8+
class TaskManager {
9+
constructor() {
10+
this.tasks = [];
11+
}
12+
13+
addTask(name, description) {
14+
console.time(`addTask`);
15+
console.log(`Trying add task: ${name}`);
16+
17+
this.tasks.push({name, description})
18+
19+
console.info(`Task "${name}" added successfully`);
20+
console.timeEnd(`addTask`);
21+
}
22+
23+
removeTask(name) {
24+
console.time(`removeTask`);
25+
console.log(`Trying remove task: ${name}`);
26+
27+
const index = this.tasks.findIndex(task => task.name === name);
28+
29+
if (index !== -1) {
30+
this.tasks.splice(index, 1);
31+
console.info(`Task "${name}" removed successfully`);
32+
} else {
33+
console.warn(`The task with the name "${name}" was not found`);
34+
}
35+
console.timeEnd(`removeTask`);
36+
}
37+
38+
listTasks() {
39+
console.time(`listTasks`);
40+
console.log(`Showing all tasks:`);
41+
42+
if (this.tasks.length === 0) {
43+
console.warn("No tasks available");
44+
} else {
45+
this.tasks.forEach(task => {
46+
console.info(`Task: ${task.name}, Description: ${task.description}`);
47+
});
48+
}
49+
console.timeEnd(`listTasks`);
50+
}
51+
}
52+
53+
const taskManager = new TaskManager();
54+
taskManager.addTask("Task 1", "Do something");
55+
taskManager.addTask("Task 2", "Do anything");
56+
57+
taskManager.listTasks();
58+
59+
taskManager.removeTask("Task 2");
60+
console.log(taskManager);

0 commit comments

Comments
 (0)