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().
The script maintains two arrays — drinks and pastries — and demonstrates the following concepts in order:
- Create the order arrays — declare
drinksandpastries. - Log counts using
.length— print how many items are in each array. - Access orders with bracket notation — combine items by hardcoded index (first/last/second).
- Access orders dynamically with variables — use
drinkIndexandpastryIndexto pick items. - Loop logging every drink using
.length— iterate the drinks array with aforloop. - Add a new order and re-track length —
.push()a new drink and read the updated length.
Prerequisites: Node.js installed.
# from the project root
node index.jsYou should see output covering each task, ending with the newly added drink.