0
0
Javascriptprogramming~10 mins

If–else statement in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
If-else statement
📖 Scenario: You are helping a small shop decide if a customer gets a discount based on their purchase amount.
🎯 Goal: Build a simple program that checks if the purchase amount is enough for a discount and shows the correct message.
📋 What You'll Learn
Create a variable to store the purchase amount.
Create a variable to store the discount threshold.
Use an if-else statement to check if the purchase amount is greater than or equal to the discount threshold.
Print a message showing if the customer gets a discount or not.
💡 Why This Matters
🌍 Real World
Stores often give discounts based on how much customers buy. This helps encourage bigger purchases.
💼 Career
Understanding if-else statements is important for making decisions in programs, like showing messages or calculating prices.
Progress0 / 4 steps
1
Create the purchase amount variable
Create a variable called purchaseAmount and set it to 120.
Javascript
Need a hint?

Use let to create the variable and assign the number 120.

2
Create the discount threshold variable
Create a variable called discountThreshold and set it to 100.
Javascript
Need a hint?

Use let to create the variable and assign the number 100.

3
Write the if-else statement
Write an if statement that checks if purchaseAmount is greater than or equal to discountThreshold. Inside the if, create a variable called message and set it to "You get a discount!". In the else part, set message to "No discount this time.".
Javascript
Need a hint?

Use if (purchaseAmount >= discountThreshold) to check the condition. Then assign the correct message inside each block.

4
Print the message
Write console.log(message) to print the message to the console.
Javascript
Need a hint?

Use console.log(message) to show the message in the console.