Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 1.12 KB

File metadata and controls

25 lines (17 loc) · 1.12 KB

Practice: Indices and Bracket Notation

A small Node.js practice exercise modeling a simple cafe order system to reinforce JavaScript array fundamentals: indices, bracket notation, .length, dynamic access via variables, looping, and mutating arrays with .push().

What it does

The script maintains two arrays — drinks and pastries — and demonstrates the following concepts in order:

  1. Create the order arrays — declare drinks and pastries.
  2. Log counts using .length — print how many items are in each array.
  3. Access orders with bracket notation — combine items by hardcoded index (first/last/second).
  4. Access orders dynamically with variables — use drinkIndex and pastryIndex to pick items.
  5. Loop logging every drink using .length — iterate the drinks array with a for loop.
  6. Add a new order and re-track length.push() a new drink and read the updated length.

How to run

Prerequisites: Node.js installed.

# from the project root
node index.js

You should see output covering each task, ending with the newly added drink.