Menu
Coddy logo textTech

Recap Challenge #1

Lesson 21 of 21 in Coddy's Slices and Maps in Golang course.

challenge icon

Challenge

Easy

Write a program that manages a library of books with the ability to add and remove books.

This program will take user input of two strings and an integer value: the first is the operation type (Add or Delete), the second is the name of the book to add or delete, and the third is the value of the book that we need to add.

  • For example, <strong>Add Rust 200</strong> means we will add a book called Rust with a value of 200.
  • Example <strong>Remove Rust</strong> means we will remove the book Rust.

Try it yourself

package main

import (
	"fmt"
)

func main() {

	// Get the user's input Don't change this!
	var operation string
	var name string
	var value int
	fmt.Scanln(&operation )
	fmt.Scanln(&name)
    fmt.Scanln(&value)
	// Map to store the books in the library Don't change this!
	library := map[string]int{
		"Golang": 134,
		"Python": 200,
		"Rust":   300,
		"Lua":    260,
		"Java":   500,
	}    
    // Check for operation Type (Add or Delete)

        // Add the book with value

	    // Delete the book 
	
}

All lessons in Slices and Maps in Golang