0
0
Rubyprogramming~15 mins

Local variables and naming conventions in Ruby - Mini Project: Build & Apply

Choose your learning style9 modes available
Local variables and naming conventions
📖 Scenario: You are helping a small bakery keep track of daily sales. You will use local variables with clear names to store and calculate the total number of bread loaves sold.
🎯 Goal: Create local variables with proper names to store daily sales numbers, add them up, and print the total loaves sold.
📋 What You'll Learn
Create local variables with lowercase letters and underscores
Use descriptive variable names for daily sales
Add the daily sales variables to get the total
Print the total number of loaves sold
💡 Why This Matters
🌍 Real World
Local variables are used everywhere in programming to store temporary information like daily sales, user input, or calculation results.
💼 Career
Clear variable naming and using local variables properly is a fundamental skill for any programmer, making your code easier to maintain and collaborate on.
Progress0 / 4 steps
1
Create local variables for daily sales
Create three local variables called monday_sales, tuesday_sales, and wednesday_sales with the values 20, 25, and 30 respectively.
Ruby
Need a hint?

Use lowercase letters and underscores for variable names. Assign the exact numbers given.

2
Create a variable for total sales
Create a local variable called total_sales and set it to the sum of monday_sales, tuesday_sales, and wednesday_sales.
Ruby
Need a hint?

Add the three daily sales variables and store the result in total_sales.

3
Print the total sales
Use puts to print the value of total_sales.
Ruby
Need a hint?

Use puts followed by the variable name to display the total.

4
Run the program and see the output
Run the program to display the total number of bread loaves sold over the three days.
Ruby
Need a hint?

The output should be the sum of 20, 25, and 30, which is 75.