0
0
Javascriptprogramming~15 mins

Unary operators in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Unary Operators in JavaScript
📖 Scenario: You are working on a simple calculator app that needs to handle increasing and decreasing numbers by one. This is common in counters, like counting items in a shopping cart or tracking steps in a game.
🎯 Goal: Build a small program that uses unary operators to increase and decrease a number by one.
📋 What You'll Learn
Create a variable with an initial number
Create a variable to hold the incremented number using the increment operator ++
Create a variable to hold the decremented number using the decrement operator --
Print the original, incremented, and decremented numbers
💡 Why This Matters
🌍 Real World
Counters are everywhere: counting clicks, items in a cart, or steps in a game. Unary operators make these tasks simple and fast.
💼 Career
Understanding unary operators is essential for writing clean and efficient code in many programming jobs, especially in frontend and backend development.
Progress0 / 4 steps
1
Create the initial number variable
Create a variable called count and set it to the number 10.
Javascript
Need a hint?

Use let to create a variable named count and assign it the value 10.

2
Create incremented number using increment operator
Create a variable called incremented and set it to count plus one using the increment operator ++.
Javascript
Need a hint?

Use the prefix increment operator ++count to add one to count and assign it to incremented.

3
Create decremented number using decrement operator
Create a variable called decremented and set it to incremented minus one using the decrement operator --.
Javascript
Need a hint?

Use the prefix decrement operator --incremented to subtract one from incremented and assign it to decremented.

4
Print all three numbers
Use console.log to print the values of count, incremented, and decremented each on a new line.
Javascript
Need a hint?

Use three console.log statements to print each variable on its own line.