Lesson contents

Modeling data

Keep the quantity and unit price together in one record. Give the two fields names so you can tell what each number means.

Simple example

Multiply two fields.

Start2 × 3
Result6
lesson.js
const item = { units: 2, price: 3 };
console.log(item.units * item.price);
Output
6
Advertisements

Everyday examples

A receipt lists four notebooks at three coins each. What is the cost of this line on the receipt?

Start4 notebooks × 3
Result12
lesson.js
const item = { units: 4, price: 3 };
console.log(item.units * item.price);
Output
12
Run the example
Terminal
node lesson.js
Official documentation