0
0
Goprogramming~15 mins

Relational operators in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Relational Operators in Go
๐Ÿ“– Scenario: You are creating a simple program to compare ages of two friends to see who is older.
๐ŸŽฏ Goal: Build a Go program that uses relational operators to compare two age values and prints the comparison results.
๐Ÿ“‹ What You'll Learn
Create two integer variables with exact values
Create a boolean variable to store a comparison result
Use relational operators to compare the two ages
Print the results of the comparisons
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Comparing values is common in programs that make decisions, like checking ages, prices, or scores.
๐Ÿ’ผ Career
Understanding relational operators is essential for any programming job because they help control the flow of logic.
Progress0 / 4 steps
1
Create age variables
Create two integer variables called ageAlice and ageBob with values 25 and 30 respectively.
Go
Need a hint?

Use := to declare and assign variables in Go.

2
Create a boolean variable for comparison
Create a boolean variable called isAliceOlder and set it to the result of comparing if ageAlice is greater than ageBob using the relational operator >.
Go
Need a hint?

Use the > operator to check if one number is greater than another.

3
Compare ages with other relational operators
Create three more boolean variables: isAliceYounger for ageAlice < ageBob, isSameAge for ageAlice == ageBob, and isNotSameAge for ageAlice != ageBob.
Go
Need a hint?

Use <, ==, and != operators for less than, equal to, and not equal to comparisons.

4
Print the comparison results
Use fmt.Println to print the values of isAliceOlder, isAliceYounger, isSameAge, and isNotSameAge each on a new line. Remember to import the fmt package.
Go
Need a hint?

Use fmt.Println(variable) to print each variable on its own line.