Each book on the shelf is a Book: a title, a page count and Done (finished or not). Write PagesRead(books) to return the total pages of the finished books. An empty shelf gives 0.
PagesRead([]Book{{"Frog", 120, true}, {"Moon", 300, false}, {"Owl", 80, true}})→200PagesRead([]Book{})→0func PagesRead(books []Book) intpackage main
type Book struct {
Title string
Pages int
Done bool
}
func PagesRead(books []Book) int {
pages := 0
for _, b := range books {
// your code here: if this book is done, add its pages to pages
}
return pages
}
Run tries the examples. When they look right, Submit.