0
0
Goprogramming~15 mins

Variable declaration using var in Go - Mini Project: Build & Apply

Choose your learning style9 modes available
Variable declaration using var
๐Ÿ“– Scenario: Imagine you are organizing a small store's inventory. You want to keep track of the number of apples you have.
๐ŸŽฏ Goal: You will declare a variable using var to store the number of apples and then display it.
๐Ÿ“‹ What You'll Learn
Declare a variable called apples using var
Set the value of apples to 10
Print the value of apples
๐Ÿ’ก Why This Matters
๐ŸŒ Real World
Declaring variables is the first step in storing and managing data in any program, like keeping track of inventory in a store.
๐Ÿ’ผ Career
Understanding variable declaration is essential for all programming jobs, as it helps in writing clear and maintainable code.
Progress0 / 4 steps
1
Declare the variable
Declare a variable called apples using var and set it to 10.
Go
Need a hint?

Use var apples int = 10 to declare and set the variable.

2
Add a helper variable
Declare a variable called storeName using var and set it to "Fruit Shop".
Go
Need a hint?

Use var storeName string = "Fruit Shop" to declare the store name.

3
Use the variables
Use fmt.Println to print the message: "We have 10 apples in Fruit Shop" by combining apples and storeName. Use fmt.Printf with formatting.
Go
Need a hint?

Use fmt.Printf("We have %d apples in %s\n", apples, storeName) to print the message.

4
Display the result
Run the program and print the output message exactly as: We have 10 apples in Fruit Shop.
Go
Need a hint?

Make sure your program prints exactly: We have 10 apples in Fruit Shop