Challenge: Basics of Variables
Task
Complete the following code so that both myVar1 and myVar2 are successfully declared and initialized.
index.go
123456789package main import "fmt" func main() { ___ myVar1 = 1 myVar2 __ 2 fmt.Println("The value of myVar1 is", myVar1) fmt.Println("The value of myVar2 is", myVar2) }
- Use
varto declare a variable. - Use
:=for short variable declaration and initialization. - Each variable needs both a name and a value.
package main
import "fmt"
func main() {
var myVar1 = 1
myVar2 := 2
fmt.Println("The value of myVar1 is", myVar1)
fmt.Println("The value of myVar2 is", myVar2)
}
Everything was clear?
Thanks for your feedback!
SectionΒ 1. ChapterΒ 10
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Suggested prompts:
Can you explain the difference between using `var` and `:=` in Go?
What happens if I try to use `:=` outside of a function in Go?
Can you show me how to declare multiple variables at once in Go?
Awesome!
Completion rate improved to 1.96
Challenge: Basics of Variables
Swipe to show menu
Task
Complete the following code so that both myVar1 and myVar2 are successfully declared and initialized.
index.go
123456789package main import "fmt" func main() { ___ myVar1 = 1 myVar2 __ 2 fmt.Println("The value of myVar1 is", myVar1) fmt.Println("The value of myVar2 is", myVar2) }
- Use
varto declare a variable. - Use
:=for short variable declaration and initialization. - Each variable needs both a name and a value.
package main
import "fmt"
func main() {
var myVar1 = 1
myVar2 := 2
fmt.Println("The value of myVar1 is", myVar1)
fmt.Println("The value of myVar2 is", myVar2)
}
Everything was clear?
Thanks for your feedback!
SectionΒ 1. ChapterΒ 10