Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Challenge: Basics of Variables | Section
Practice
Projects
Quizzes & Challenges
Quizer
Challenges
/
Getting Started with Go

bookChallenge: Basics of Variables

Sveip for å vise menyen

Task

Complete the following code so that both myVar1 and myVar2 are successfully declared and initialized.

index.go

index.go

copy
123456789
package 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) }
  1. Use var to declare a variable.
  2. Use := for short variable declaration and initialization.
  3. 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)
}
Alt var klart?

Hvordan kan vi forbedre det?

Takk for tilbakemeldingene dine!

Seksjon 1. Kapittel 9

Spør AI

expand

Spør AI

ChatGPT

Spør om hva du vil, eller prøv ett av de foreslåtte spørsmålene for å starte chatten vår

Seksjon 1. Kapittel 9
some-alt