Kodewick
Start learning →
Basic←→0 / 70

Books finished

#052BasicStructsLoops3 min

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.

Examples
PagesRead([]Book{{"Frog", 120, true}, {"Moon", 300, false}, {"Owl", 80, true}})→200
PagesRead([]Book{})→0
The functionfunc PagesRead(books []Book) int
main.go
package 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
}
Ctrl + Enter runs too
Result

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