Kodewick
Start learning →
Starter←→0 / 70

Garden bed area

#050StarterStructs3 min

The garden has two rectangular beds. Write the method Area() on Bed to return the bed's area (width times length); main shows each bed's area.

Should show
6
20
main.go
package main

import "fmt"

type Bed struct {
	Width  int
	Length int
}

func (b Bed) Area() int {
	// your code here: return b's width times its length
	return 0
}

func main() {
	beds := []Bed{{2, 3}, {4, 5}}
	for _, b := range beds {
		fmt.Println(b.Area())
	}
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.