0
0
Goprogramming~15 mins

If–else statement in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
If-else statement
📖 Scenario: You are creating a simple program to check if a person is old enough to vote. Voting age is 18 years or older.
🎯 Goal: Build a Go program that uses an if-else statement to check a person's age and print whether they can vote or not.
📋 What You'll Learn
Create an integer variable called age with the value 20
Create an integer variable called votingAge with the value 18
Use an if-else statement to compare age with votingAge
Print "You can vote!" if age is greater than or equal to votingAge
Print "You cannot vote yet." if age is less than votingAge
💡 Why This Matters
🌍 Real World
Checking age eligibility is common in many applications like voting, driving, or buying age-restricted items.
💼 Career
Understanding if-else statements is fundamental for decision-making in programming jobs.
Progress0 / 4 steps
1
Create the age variable
Create an integer variable called age and set it to 20.
Go
Need a hint?

Use age := 20 inside the main function to create the variable.

2
Create the votingAge variable
Create an integer variable called votingAge and set it to 18.
Go
Need a hint?

Use votingAge := 18 inside the main function after age.

3
Write the if-else statement
Use an if-else statement to check if age is greater than or equal to votingAge. Use if age >= votingAge and else blocks.
Go
Need a hint?

Use if age >= votingAge { ... } else { ... } and inside print the correct messages.

4
Print the result
Run the program to print the correct voting message based on the if-else condition.
Go
Need a hint?

Just run the program. It will print the voting message.