Below you will see an anonymous function assigned to the increment variable. However, there is a shadowed variable within the anonymous function declaration — find the shadowed variable and fix it so it doesn't shadow the variable from the outer scope anymore.
Anonymous functions and Closures
Old newIncrement
Report a typo
Sample Input 1:
2Sample Output 1:
5Write a program in Go
package main
import "fmt"
func main() {
var number int
fmt.Scan(&number)
// Find the shadowed variable within the anonymous function below and fix it:
increment := func() {
number := number * 2 // nolint: gocritic
number++
}
increment()
fmt.Println(number)
}
___
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.
Create a free account to access the full topic
By continuing, you agree to the JetBrains Academy Terms of Service as well as Hyperskill Terms of Service and Privacy Policy.