Skip to content

About

JavaScript Homework 6 — Object-Oriented Programming (OOP) and Classes: Practical tasks focused on mastering JavaScript object-oriented programming concepts, including this context, classes, instances, private properties, getters/setters, static methods, and prototype-based behavior.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

📘 JavaScript Homework 6 — Object Oriented Programming

This repository contains solutions for 3 tasks focused on Object-Oriented Programming (OOP) concepts in JavaScript. The homework covers this context, classes, private properties, class methods, and encapsulation. Each task is implemented in a separate file: task-1.js, task-2.js, task-3.js.


🚀 Overview

After completing Module 6, you are almost at the core of JavaScript 💪 This homework reinforces your understanding of:

  • The this keyword in different contexts
  • this in global scope, object methods, arrow functions, and callbacks
  • The call, apply, and bind methods
  • Object-Oriented Programming fundamentals
  • Classes, instances, and public interfaces
  • Prototypes and prototypal inheritance
  • Creating objects of the same type with shared behavior and different data

The final step is to correctly use this, build classes for managing data, and work with string constructors.


🔹 Task 1: User Account (task-1.js)

Refactor an existing object to correctly use the this keyword. The task simulates a real-world scenario where a developer left broken code for managing user accounts in a food delivery service.

You must fix object methods so they properly access and update object properties using this.

const customer = {
  username: "Mango",
  balance: 24000,
  discount: 0.1,
  orders: ["Burger", "Pizza", "Salad"],
};

✅ What was practiced:

  • Correct usage of this inside object methods
  • Updating object state via methods
  • Working with arrays and numeric calculations inside an object

✅ Expected behavior:

  • Getting and updating balance and discount
  • Adding new orders
  • Returning updated orders list

🔹 Task 2: Storage (task-2.js)

Create a Storage class to manage a warehouse inventory. The class stores items in a private property and provides a clean public interface for interaction.

Defined methods:

  • getItems() — returns the current list of items
  • addItem(newItem) — adds a new item to storage
  • removeItem(itemToRemove) — removes an item by name
const storage = new Storage(["Nanitoids", "Prolonger", "Antigravitator"]);
console.log(storage.getItems());
storage.addItem("Droid");
storage.removeItem("Prolonger");

✅ What was practiced:

  • Creating classes with constructors
  • Using private class fields
  • Encapsulation and controlled access to data
  • Modifying internal state through class methods

🔹 Task 3: String Builder (task-3.js)

Create a StringBuilder class for flexible string manipulation. The class stores a string in a private property and provides methods to modify it from different sides.

Defined methods:

  • getValue() — returns the current string value
  • padStart(str) — adds a string to the beginning
  • padEnd(str) — adds a string to the end
  • padBoth(str) — adds a string to both beginning and end
const builder = new StringBuilder(".");
builder.padStart("^");
builder.padEnd("^");
builder.padBoth("=");

✅ What was practiced:

  • Working with private class fields
  • String manipulation inside class methods
  • Designing a clear and minimal public API

📌 Summary & Reflection

With this homework, you practiced core Object-Oriented Programming concepts in JavaScript:

  • Proper usage of this
  • Building reusable classes
  • Encapsulation with private properties
  • Clean and predictable class interfaces
  • Real-world scenarios using objects and classes

These tasks strengthen your understanding of OOP and prepare you for building scalable, maintainable JavaScript applications 🚀

About

JavaScript Homework 6 — Object-Oriented Programming (OOP) and Classes: Practical tasks focused on mastering JavaScript object-oriented programming concepts, including this context, classes, instances, private properties, getters/setters, static methods, and prototype-based behavior.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages