We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Basic Variables

Some of Go's most common variable types are:

  • int: a signed integer
  • bool: a boolean value, either true or false
  • string: a sequence of characters
  • float64: a floating-point number
  • byte: exactly what it sounds like: 8 bits of data

And to use them, their values are set like this:

var health int
health = 100

var isAwesome bool
isAwesome = true

var greeting string
greeting = "Hello, world!"

var pi float64
pi = 3.14159

var data byte
data = 0xFF

Don't worry, we'll talk about a better way to declare variables in the next lesson.

Assignment

Run (but don't submit yet) the code. Notice that the username is blank!

Set the username variable to the value "eddie_cabot". Then submit the fixed code.