0
0
Goprogramming~15 mins

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

Choose your learning style9 modes available
Else-if ladder
📖 Scenario: You are building a simple program to categorize a person's age group based on their age. This is like sorting people into groups such as child, teenager, adult, or senior.
🎯 Goal: Create a Go program that uses an else-if ladder to check a person's age and print the correct age group.
📋 What You'll Learn
Create an integer variable called age with the value 25
Create a string variable called ageGroup to store the age category
Use an else-if ladder with if, else if, and else to assign the correct age group to ageGroup
Print the value of ageGroup
💡 Why This Matters
🌍 Real World
Age group categorization is common in apps that provide age-specific content or services, like games, health apps, or social platforms.
💼 Career
Understanding else-if ladders helps in decision-making logic, which is essential for software development, data processing, and user input validation.
Progress0 / 4 steps
1
DATA SETUP: Create the age variable
Create an integer variable called age and set it to 25.
Go
Need a hint?

Use var age int = 25 to create the variable.

2
CONFIGURATION: Create the ageGroup variable
Create a string variable called ageGroup and set it to an empty string "".
Go
Need a hint?

Use var ageGroup string = "" to create the variable.

3
CORE LOGIC: Use an else-if ladder to assign ageGroup
Use an else-if ladder with if, else if, and else to assign ageGroup as follows: if age < 13, set ageGroup = "Child"; else if age < 20, set ageGroup = "Teenager"; else if age < 60, set ageGroup = "Adult"; else set ageGroup = "Senior".
Go
Need a hint?

Use if, else if, and else blocks to check the age ranges and assign ageGroup.

4
OUTPUT: Print the ageGroup
Write a fmt.Println statement to print the value of ageGroup.
Go
Need a hint?

Use fmt.Println(ageGroup) to print the age group.