Skip to content

Commit 5251d01

Browse files
committed
#25 - TypeScript
1 parent 9b963d3 commit 5251d01

File tree

1 file changed

+67
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)