Challenge - 5 Problems
Assignment Operator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of compound assignment with addition
What is the output of this Go program?
Go
package main import "fmt" func main() { x := 10 x += 5 fmt.Println(x) }
Attempts:
2 left
๐ก Hint
The += operator adds the right value to the left variable.
โ Incorrect
The operator x += 5 adds 5 to x, so x becomes 15.
โ Predict Output
intermediate2:00remaining
Output of compound assignment with bitwise AND
What is the output of this Go program?
Go
package main import "fmt" func main() { a := 12 // binary 1100 a &= 5 // binary 0101 fmt.Println(a) }
Attempts:
2 left
๐ก Hint
Bitwise AND keeps bits set in both numbers.
โ Incorrect
12 (1100) & 5 (0101) = 4 (0100).
โ Predict Output
advanced2:00remaining
Value after multiple compound assignments
What is the value of variable x after running this Go code?
Go
package main import "fmt" func main() { x := 3 x *= 4 x -= 5 x /= 2 fmt.Println(x) }
Attempts:
2 left
๐ก Hint
Apply each operation step by step.
โ Incorrect
x starts at 3, then x *= 4 โ 12, x -= 5 โ 7, x /= 2 โ 3 (integer division), but Go integer division truncates so 7/2=3, so output is 3.
โ Predict Output
advanced2:00remaining
Output of compound assignment with string concatenation
What is the output of this Go program?
Go
package main import "fmt" func main() { s := "Go" s += "lang" fmt.Println(s) }
Attempts:
2 left
๐ก Hint
The += operator concatenates strings in Go.
โ Incorrect
The string s is "Go" and += "lang" appends "lang" to it, resulting in "Golang".
โ Predict Output
expert2:00remaining
Output of compound assignment with float division and type conversion
What is the output of this Go program?
Go
package main import "fmt" func main() { var x float64 = 10.0 var y int = 4 x /= float64(y) fmt.Printf("%.2f", x) }
Attempts:
2 left
๐ก Hint
Remember to convert int to float64 before division.
โ Incorrect
x is 10.0, y is 4. After x /= float64(y), x becomes 2.5. The Printf formats it to 2 decimal places: 2.50.