• 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

Exercise: Private Budget Ledger

Private Budget Ledger

After the seat-ledger demo, make a different closure: a spending desk. makeBudget(startingBalance) returns a spend(amount) function that subtracts affordable expenses and returns the new balance. If there is not enough money, return null and leave the balance unchanged. Use positive amounts and nonnegative starting balances in this exercise. Work only in script.js; Run shows your checkpoints in the Console.

A different example

This separate example shows a closure keeping a message prefix, not money:

javascript
function makeTag(prefix) {
  return function (word) { return `${prefix}: ${word}`; };
}
const label = makeTag("Review");
console.log(label("ready")); // Review: ready

Your Task

  1. Define makeBudget(startingBalance) returning a spending function.
  2. Make repeated calls to the same returned function share remaining balance.
  3. Reject expenses larger than the remaining amount with null without deducting them.
  4. Log Independent: 8,19 by spending from two fresh budgets.

Section complete

Backstage Toolkit complete: your functions now combine results, supply defaults, and remember private state. Take the section quiz before moving to arrays.

Hint 1
1 / 1
HINT 1

Read each expected Console line, then build it from your function calls.

Take the Quiz →
Loading editor…
Press Run to execute your code.
READY
intercourses
javascript