0
0
Goprogramming~10 mins

Increment and decrement in Go - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to increment the variable count by 1.

Go
package main

import "fmt"

func main() {
    count := 5
    count[1]
    fmt.Println(count)
}
Drag options to blanks, or click blank then click option'
A++
B+=
C++=
D--
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '+=' causes a syntax error because it requires an operand like 1 after it.
Using '--' decreases the value instead of increasing.
2fill in blank
medium

Complete the code to decrement the variable num by 1 using the correct operator.

Go
package main

import "fmt"

func main() {
    num := 10
    num[1] 1
    fmt.Println(num)
}
Drag options to blanks, or click blank then click option'
A-=
B+=
C++
D--
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '--' with a value causes syntax error.
Using '+=' increases the value instead of decreasing.
3fill in blank
hard

Fix the error in the code to correctly increment value by 1.

Go
package main

import "fmt"

func main() {
    value := 3
    value [1]
    fmt.Println(value)
}
Drag options to blanks, or click blank then click option'
A--
B++
C++ 1
D+= 1
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '++' causes syntax error due to the space separating variable and operator.
Using '++ 1' is invalid syntax.
4fill in blank
hard

Fill both blanks to create a map of words to their lengths, including only words longer than 3 characters.

Go
package main

import "fmt"

func main() {
    words := []string{"go", "code", "play", "fun"}
    lengths := make(map[string]int)
    for _, word := range words {
        if len(word) > 3 {
            lengths[[1]] = len([2])
        }
    }
    fmt.Println(lengths)
}
Drag options to blanks, or click blank then click option'
A"word"
Bword
Cwords
D"words"
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using '"word"' (quoted literal) instead of variable word for dynamic key.
Using the whole list 'words' instead of the current 'word' for length.
5fill in blank
hard

Fill all three blanks to create a map of uppercase words to their lengths, including only words longer than 3 characters.

Go
package main

import (
    "fmt"
    "strings"
)

func main() {
    words := []string{"go", "code", "play", "fun"}
    lengths := make(map[string]int)
    for _, word := range words {
        if len(word) [3] 3 {
            lengths[[1]] = [2]
        }
    }
    fmt.Println(lengths)
}
Drag options to blanks, or click blank then click option'
Astrings.ToUpper(word)
Blen(word)
C>
Dword
Attempts:
3 left
๐Ÿ’ก Hint
Common Mistakes
Using the original word instead of uppercase as key.
Using '<' instead of '>' in the condition.