• in
InterCourses
CoursesBlogs
0
← Introduction to JavaScript
○What is JavaScript?○Your First JavaScript Code○Data Types○Type Checking○Inspect Values in the Console○Inspect the Queue Report○Trace a Faulty Calculation○Repair the Score Calculation✦Module Quiz
○Declaring Variables○let and const in Practice○Operators○Type Conversion○Group and Convert Expense Inputs○Calculate the Event Expense Total○Track a Changing Points Tally○Adjust a Ticket Price✦Module Quiz
○Conditionals○Demo: Combined Conditions Before FizzBuzz○Challenge: FizzBuzz Announcer○Switch Statement○Demo: Switch a Venue Sign○Challenge: Power Loadout○For Loops○While Loop○Break and Continue○Demo: Stop a Ticket Scan○Challenge: Number Guess Referee○Demo: Rainfall Routing Walkthrough○Exercise: Score Batch Report✦Module Quiz
○Defining Functions○Arrow Functions○Scope○Closures○Project - Calculator○Function Expressions○Demo: Ticket Pricing Walkthrough○Exercise: Shipping Labels with Defaults○Demo: Seat Ledger Closure Walkthrough○Exercise: Private Budget Ledger✦Module Quiz
○Arrays○Demo: Student Scoreboard○Challenge: Student Course Scoreboard○Array Mutation Methods○Array Slice and Concat○Array Iteration Methods○Multidimensional Arrays○Destructuring○Array Reverse and Sort○Array Fill○Array Find and Includes○Array Flat and FlatMap○Array Reduce, Some, and Every○Demo: Charging Rack Restock Report○Exercise: Pantry Restock Plan✦Module Quiz
○Object Key-Value Pairs○Student Course Record○Object Methods and Destructuring○Map and Set Collections○Playlist Lookup○Number and BigInt Boundaries○Ticket Ledger○JSON○Math and Date○Date Basics○Demo: Supply Bin Audit○Exercise: Volunteer Shift Audit○Demo: Workshop Attendance Feed○Exercise: Parcel Scan Feed✦Module Quiz
○String Methods○Template Literals○Regular Expressions○Demo: Build a Reminder with Template Literals○Exercise: Format Pantry Pickup Messages○Demo: Validate a Time Slot with Regex○Exercise: Validate Storage Shelf Labels✦Module Quiz
○Higher-Order Functions○Callbacks○map, filter, and reduce○Demo: Student Register with map○Challenge: Student Register○Recursion○Project - Data Transform Pipeline○Demo: Handle an Error-First Callback○Exercise: Report Seat Reservation Results○Demo: Summarize Completed Bike Rides○Exercise: Summarize Delivered Parcels✦Module Quiz
○Demo: A notebook object○OOP Introduction○Demo: Independent workshop passes●Classes○Demo: An inherited notice○Inheritance○Demo: A private seat counter○Encapsulation○Demo: Equipment desk checkout○Project: Library Checkout✦Module Quiz
○Demo: Callback Timing○Exercise: Asynchronous JavaScript○Demo: Promise Rehearsal○Exercise: Promises and Async Await○Demo: Offline API Coordination○Exercise: Async API Simulation○Demo: Partial Results Bulletin○Project: Resilient Awards Feed○Demo: Retry a Local Delivery○Project: Reliable Score Delivery✦Module Quiz

Classes

The workshop-pass demo made separate objects from one class. Now model a bank account in script.js, checking each balance change in the Console.

Classes provide syntax for creating independent objects with shared methods. Private fields, getters, and setters come later in this module.

Basic class

javascript
class WorkshopSession {
  constructor(topic, seats) {
    this.topic = topic;
    this.seats = seats;
  }
}

console.log(new WorkshopSession("Testing", 12).topic);

Your Task

  1. Store the owner and starting balance in the BankAccount constructor. The starter logs Alice’s owner name.
  2. Add getBalance() to return the balance; the starter checks the initial balance of 100.
  3. Make deposit(amount) add positive amounts; the starter deposits 50 into an empty account.
  4. Make deposit(amount) ignore negative amounts; the starter tries deposit(-20) on a balance of 100.
  5. Make withdraw(30) reduce a balance of 100 to 70 and return true. The starter checks both values.
  6. Deny an overdraw without changing the balance; the starter tries withdraw(100) on 50.
  7. Deny nonpositive withdrawals; the starter tries withdraw(-1) on 50.
  8. Implement toString() to return BankAccount(owner: Alice, balance: $120) after Alice’s deposit and withdrawal. The starter logs its result.
  9. Log mission result: BankAccount(owner: Alice, balance: $120) on its own Console line.
Hint 1
1 / 3
HINT 1

Class syntax: class Name { constructor(...) { this.prop = val; } }

HINT 2

Methods go directly in the class body — no commas between them.

HINT 3

Create instances with new: const obj = new MyClass(args);

Loading editor…
Press Run to execute your code.
READY
intercourses
javascript