Signup/Sign In
Ask Question
Not satisfied by the Answer? Still looking for a better solution?

Help with "Shorthand Variable Declaration" in Go Lang

Hi everyone, Hope you are all well. I've been struggling with Shorthand Variable Declaration in Go Lang.

Here is my code:*

package main

import "fmt"

func main() {

// full style variable declaration
var quantity int

// after confirming with user
quantity = 4

length, width := 1.4, 1.2


var customerName = "John Wick"

fmt.Println(customerName)
fmt.Println("has ordered", quantity, "towels")
fmt.Println("each with area of")
fmt.Println(length*width, "square feet")

}


*The code is saying line number 11 is the problem can anyone tell me what is wrong
by

1 Answer

sam5epi0l
Your code is seems correct.
I can provide what I used to move to the next lesson:

package main

import "fmt"

func main() {

// full style variable declaration
var quantity int

// after confirming with user
quantity = 4

length, width := 1.4, 1.2


var customerName = "John Wick"

fmt.Println(customerName)
fmt.Println("has ordered", quantity, "towels")
fmt.Println("each with area of")
fmt.Println(length*width, "square feet")

}


Let me know if it works!

Login / Signup to Answer the Question.