0
0
Javascriptprogramming~15 mins

Assignment operators in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Assignment Operators in JavaScript
📖 Scenario: You are managing a small online store's inventory. You want to update the stock quantities using assignment operators to make your code shorter and clearer.
🎯 Goal: Learn how to use assignment operators like +=, -=, *=, and /= to update variables efficiently.
📋 What You'll Learn
Create variables with initial stock values
Create a variable for the number of items sold
Use assignment operators to update stock values
Print the final stock values
💡 Why This Matters
🌍 Real World
Updating inventory counts quickly and clearly is important in managing stores or warehouses.
💼 Career
Understanding assignment operators helps write cleaner code for tasks like updating values, counters, or calculations in many programming jobs.
Progress0 / 4 steps
1
Create initial stock variables
Create three variables called apples, oranges, and bananas with initial values 50, 30, and 20 respectively.
Javascript
Need a hint?

Use let to declare variables and assign the exact numbers.

2
Create a variable for items sold
Create a variable called sold and set it to 5 to represent the number of items sold for each fruit.
Javascript
Need a hint?

Declare sold with the value 5 using let.

3
Update stock using assignment operators
Use the assignment operator -= to subtract sold from each of the variables apples, oranges, and bananas.
Javascript
Need a hint?

Use variable -= sold; to reduce each fruit's stock.

4
Print the updated stock values
Use console.log to print the values of apples, oranges, and bananas separated by spaces.
Javascript
Need a hint?

Use console.log(apples, oranges, bananas); to print the values separated by spaces.