0
0
Javascriptprogramming~15 mins

Else–if ladder in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Else-if ladder
📖 Scenario: You are creating a simple program that gives a message based on the temperature outside. This helps people decide what to wear.
🎯 Goal: Build a program that uses an else if ladder to check the temperature and print the right message.
📋 What You'll Learn
Create a variable called temperature with a number value.
Create a variable called message to store the result message.
Use an else if ladder to set message based on temperature:
temperature >= 30 -> message is "It's very hot outside."
temperature >= 20 -> message is "The weather is warm."
temperature >= 10 -> message is "It's a bit chilly."
Otherwise, message is "It's cold outside."
Print the message.
💡 Why This Matters
🌍 Real World
Checking temperature and giving advice is common in weather apps and smart home devices.
💼 Career
Understanding conditional logic like else if ladders is essential for programming decisions in many software projects.
Progress0 / 4 steps
1
Create the temperature variable
Create a variable called temperature and set it to the number 25.
Javascript
Need a hint?

Use let temperature = 25; to create the variable.

2
Create the message variable
Create a variable called message and set it to an empty string "".
Javascript
Need a hint?

Use let message = ""; to create the variable.

3
Use else if ladder to set the message
Use an if statement with an else if ladder to set message based on temperature as follows:
- If temperature >= 30, set message = "It's very hot outside."
- Else if temperature >= 20, set message = "The weather is warm."
- Else if temperature >= 10, set message = "It's a bit chilly."
- Else, set message = "It's cold outside."
Javascript
Need a hint?

Use if, else if, and else to check the temperature ranges and set the message.

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.