0
0
Javascriptprogramming~15 mins

Nested conditional statements in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Nested Conditional Statements
📖 Scenario: You are building a simple program to check the weather and temperature to decide what to wear.
🎯 Goal: Create a program that uses nested conditional statements to decide clothing advice based on weather and temperature.
📋 What You'll Learn
Create a variable weather with the exact value "rainy"
Create a variable temperature with the exact value 15
Use a nested if statement to check weather and then temperature
Print the exact advice string based on conditions
💡 Why This Matters
🌍 Real World
Weather apps and smart assistants use nested conditions to give advice based on multiple factors like weather and temperature.
💼 Career
Understanding nested conditional statements is essential for programming logic in many jobs like web development, app development, and automation.
Progress0 / 4 steps
1
Create weather and temperature variables
Create a variable called weather and set it to the string "rainy". Also create a variable called temperature and set it to the number 15.
Javascript
Need a hint?

Use let to create variables and assign the exact values.

2
Add a variable for warm temperature threshold
Create a variable called warmThreshold and set it to the number 20.
Javascript
Need a hint?

This variable will help us decide if it is warm or cold.

3
Write nested if statements for clothing advice
Use a nested if statement: first check if weather is "rainy". Inside that, check if temperature is greater than warmThreshold. If yes, set a variable advice to "Take an umbrella but wear light clothes.". Otherwise, set advice to "Take an umbrella and wear a coat.". If weather is not "rainy", set advice to "No umbrella needed.".
Javascript
Need a hint?

Remember to use === for comparison and nest the second if inside the first.

4
Print the clothing advice
Write a console.log statement to print the value of the variable advice.
Javascript
Need a hint?

Use console.log(advice); to print the advice.