Modul 2 — Kuis Interaktif

Belajar variable, ask/answer, percabangan, dan tampilan skor.

Goal Modul

Membuat kuis 5 pertanyaan: simpan skor, tampilkan skor akhir, dan simpan highscore.

Persiapan Sprite

Langkah 1 — Inisialisasi

// Host
when green flag clicked
set [score v] to 0
set [questionIndex v] to 1
if <(highscore) = ( )> then set [highscore v] to 0  // buat jika belum ada
broadcast [show_question]
    

Langkah 2 — Menyimpan soal & jawaban (cara praktis)

Di Scratch kita tidak punya object array native selain lists. Untuk tutorial ini gunakan list questions dan answers (jawaban benar per index).

// Buat list [questions] dan list [answers]
// Tambah item:
add [Siapa penemu lampu?] to [questions v]
add [Edison] to [answers v]
// Lanjutkan sampai 5 soal
    

Langkah 3 — Tampilkan pertanyaan

// Host
when I receive [show_question]
if <(questionIndex) > (length of [questions v])> then
  broadcast [end_quiz]
else
  set [qtext v] to (item (questionIndex) of [questions v])
  say (qtext) for 4 seconds
  // Atau tampilkan pilihan A/B/C pada tombol
end
    

Langkah 4 — Cek jawaban & update skor

// Tombol A (contoh)
when this sprite clicked
set [selected v] to [A]
if <(selected) = (item (questionIndex) of [answers v])> then
  change [score v] by 10
  broadcast [correct]
else
  broadcast [wrong]
end
broadcast [next_question]

// Host ketika next_question:
when I receive [next_question]
change [questionIndex v] by 1
broadcast [show_question]
    

Langkah 5 — Selesai & highscore

// Host
when I receive [end_quiz]
say join "Nilai akhir: " (score) for 4 seconds
if <(score) > (highscore)> then
  set [highscore v] to (score)
  say "Rekor baru!" for 2 secs
end
    

Tugas Praktik

  1. Buat 5 pertanyaan sendiri (tema TIK)
  2. Tambahkan timer per soal (variable timer) — otomatis waktu habis dianggap salah.
  3. Tambahkan suara ketika jawaban benar/salah.

Tips debugging