Go course

EnumsQuiz: Enums

Go

Display

Theme

Enums · Quiz

Quiz: Enums

Test what you know about iota, the String() method, validation, and switch on enums. Answer every question in the panel on the right.

  1. Question 1 of 5What is the value of Platinum?
    type Tier int
    
    const (
    	_ Tier = iota
    	Perunggu
    	Perak
    	Emas
    	Platinum
    )
  2. Question 2 of 5What is the value of Eksekusi?
    type Izin int
    
    const (
    	Baca Izin = 1 << iota
    	Tulis
    	Eksekusi
    )
  3. Question 3 of 5What happens if an enum's String() method is written like this?
    func (w Warna) String() string {
    	return fmt.Sprintf("Warna(%v)", w)
    }
  4. Question 4 of 5Why do many Go programmers reserve an enum's 0 value for 'unknown'?
  5. Question 5 of 5A new constant Dikembalikan is added to the StatusPesanan enum. What does the Go compiler do about old switch statements that don't handle it yet?