Goal Modul
Membuat kuis 5 pertanyaan: simpan skor, tampilkan skor akhir, dan simpan highscore.
Persiapan Sprite
- Sprite Host (untuk menampilkan pertanyaan)
- 3 sprite tombol jawaban: A, B, C
- Variabel:
score,questionIndex,highscore
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
- Buat 5 pertanyaan sendiri (tema TIK)
- Tambahkan timer per soal (variable
timer) — otomatis waktu habis dianggap salah. - Tambahkan suara ketika jawaban benar/salah.
Tips debugging
- Gunakan
say (variable)untuk melihat nilai variable saat runtime. - Periksa urutan broadcast — salah urut sering bikin soal tidak muncul.