Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add first lab for OOP in frontend cert #588

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
76 changes: 76 additions & 0 deletions frontend-cert/js-projects/first-oop-lab/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
const projectStatus = Object.freeze({
PENDING: Symbol("Pending Execution"),
SUCCESS: Symbol("Executed Successfully"),
FAILURE: Symbol("Execution Failed"),
});

class ProjectIdea {
constructor(title, description) {
this.title = title;
this.description = description;
this.status = projectStatus.PENDING;
}

updateProjectStatus(newStatus) {
this.status = newStatus;
}
}

class ProjectIdeaBoard {
constructor(title) {
this.title = title;
this.ideas = [];
}

pin(newIdea) {
this.ideas.push(newIdea);
}

unpin(idea) {
this.ideas.splice(this.ideas.indexOf(idea), 1);
}

count() {
return this.ideas.length;
}

toString() {
let representation = `${this.title} has ${this.count()} idea${this.count() > 1 ? "s" : ""} ->\n`;

this.ideas.forEach(
(idea) =>
(representation += `${idea.title} (${idea.status.description}) - ${idea.description}\n`),
);
return representation;
}
}

let windowLocks = new ProjectIdea(
"Smart Window Locks",
"An automation project allowing users to lock, unlock windows automatically based on weather conditions.",
);

let breakfastChef = new ProjectIdea(
"Breakfast Chef Robot",
"A robot that can follow a given list of instructions and prepare breakfast for the user and let them know through their phone.",
);
breakfastChef.updateProjectStatus(projectStatus.FAILURE);

let usedVideoGamesStore = new ProjectIdea(
"Online Used Video Games Store",
"An online platform where users can buy second hand physical copies of video games from other users.",
);
usedVideoGamesStore.updateProjectStatus(projectStatus.SUCCESS);

let hardwareProjectIdeas = new ProjectIdeaBoard("Hardware Project Board");
hardwareProjectIdeas.pin(windowLocks);
hardwareProjectIdeas.pin(breakfastChef);

let softwareProjectIdeas = new ProjectIdeaBoard("Software Project Board");
softwareProjectIdeas.pin(usedVideoGamesStore);

console.log(softwareProjectIdeas.toString());

console.log(hardwareProjectIdeas.toString());
hardwareProjectIdeas.unpin(breakfastChef);
console.log(hardwareProjectIdeas.toString());
25 changes: 25 additions & 0 deletions frontend-cert/js-projects/first-oop-lab/user-stories.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
You should define a constant of type ENUM named `projectStatus` with the different project statuses you want to have such as `PENDING`, `SUCCESS`, or `FAILURE` with ypur preferred descriptions.

You should define a class named `ProjectIdea` with a `constructor` that takes a `title` and a `description`, both strings. The class should also have a property named `status` also of type string.

You should define a method named `updateProjectStatus` inside the `ProjectIdea` class that takes accepts a string `newStatus` as parameter and can update the project idea status.

You should define a `ProjectIdeaBoard` class with a `constructor` that accepts a string `title` and initializes an empty array named `ideas` to hold instances of the `ProjectIdea` class.

You should define a method named `pin` inside the `ProjectIdeaBoard` class that accepts an instance of the `ProjectIdea` class and pushes the given instance to the `ideas` array.

You should define a method named `unpin` inside the `ProjectIdeaBoard` class that accepts an instance of the `ProjectIdea` class and removes the given instance from the `ideas` array.

You should define a method named `count` that returns the number of project ideas in a given project idea board object.

You should define a method named `toString` that returns the name of the projects ideas, their description and status as a nicely formatted string.

You should create one or more instance of the `ProjectIdeaBoard` class.

You should create one or more instance of the `ProjectIdea` class and `pin` each of them to any one of the `ProjectIdeaBoard` instances.

You should not `pin` one instance ot the `ProjectIdea` class to multiple instances of the `ProjectIdeaBoard` class.

You should `unpin` random instances of the `ProjecIdea` class from their respective boards.

You should examine the boards before and after pinning and unpinning of new project ideas.