Keanu is writing his most famous quotes!

Report a typo

Keanu Reeves wants to write three of his most famous quotes contained in the slice of strings quotes to the keanu_quotes.txt file.

Can you help Keanu implement the additional code required to write strings line by line to the file?

Take notice that Keanu has already written the code required to open keanu_quotes.txt in read-and-write mode and assigned it to the file variable.

Write a program
package main

import (
"fmt"
"log"
"os"
)

func main() {
// DO NOT DELETE! This opens the 'keanu_quotes.txt' file in read-write mode
file, err := os.OpenFile("keanu_quotes.txt", os.O_RDWR|os.O_CREATE, 0644)
if err != nil {
log.Fatal(err)
}
defer file.Close()

quotes := []string{"You're breathtaking!",
"Wake up Samurai! We have a city to burn.",
"Lose? I don't lose; I win! I'm a lawyer, that's my job, that's what I do!",
}

for _, line := range ? { // iterate over each line of the 'quotes' slice here
_, err := fmt.Fprintln(?, ?) // // write each line of the 'quotes' slice of strings to 'file' here
if err != nil {
log.Fatal(err) // exit if we have an unexpected error
}
}
}

___

Create a free account to access the full topic