Go course

ConditionalsQuiz: Conditionals

Go

Display

Theme

Conditionals · Quiz

Quiz: Conditionals

Test what you know about if, else, logical operators, and switch. Answer every question in the right-hand panel.

  1. Question 1 of 6What does the following code print?
    stok := 0
    if stok > 10 {
    	fmt.Println("banyak")
    } else if stok > 0 {
    	fmt.Println("sedikit")
    } else {
    	fmt.Println("habis")
    }
  2. Question 2 of 6Why does the following code fail to compile?
    if total := 5 * 2000; total > 8000 {
    	fmt.Println("mahal")
    }
    fmt.Println(total)
  3. Question 3 of 6If a is false, does cekServer() get called in the following expression?
    if a && cekServer() {
    	// ...
    }
  4. Question 4 of 6What does the following code print?
    nilai := 85
    switch {
    case nilai >= 60:
    	fmt.Println("C")
    case nilai >= 80:
    	fmt.Println("A")
    default:
    	fmt.Println("E")
    }
  5. Question 5 of 6What does the following code print?
    switch level := 2; level {
    case 2:
    	fmt.Print("dua ")
    	fallthrough
    case 3:
    	fmt.Print("tiga ")
    case 4:
    	fmt.Print("empat ")
    }
  6. Question 6 of 6In a Go switch, what happens after a matching case finishes running?