0
0
Rubyprogramming~30 mins

If, elsif, else statements in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
If, elsif, else statements
📖 Scenario: You are creating a simple program that decides what to wear based on the weather temperature.
🎯 Goal: Build a Ruby program that uses if, elsif, and else statements to suggest clothing based on temperature.
📋 What You'll Learn
Create a variable called temperature with an integer value.
Create a variable called hot_threshold with an integer value.
Use if, elsif, and else statements to decide clothing.
Print the clothing suggestion.
💡 Why This Matters
🌍 Real World
Decision making based on conditions is common in apps that respond to user input or environmental data, like weather apps.
💼 Career
Understanding conditional statements is essential for programming logic in any software development role.
Progress0 / 4 steps
1
DATA SETUP: Create the temperature variable
Create a variable called temperature and set it to 30.
Ruby
Need a hint?

Use temperature = 30 to create the variable.

2
CONFIGURATION: Create the hot_threshold variable
Create a variable called hot_threshold and set it to 25.
Ruby
Need a hint?

Use hot_threshold = 25 to create the variable.

3
CORE LOGIC: Use if, elsif, else to decide clothing
Use if, elsif, and else statements with the variables temperature and hot_threshold to create a variable called clothing that is:
- "Wear shorts" if temperature is greater than hot_threshold
- "Wear a jacket" if temperature is between 15 and hot_threshold (inclusive)
- "Wear a coat" if temperature is less than 15
Ruby
Need a hint?

Use if, elsif, and else with comparisons to set clothing.

4
OUTPUT: Print the clothing suggestion
Write a puts statement to print the value of the variable clothing.
Ruby
Need a hint?

Use puts clothing to print the suggestion.