Latihan 2: Actions Svelte — Svelte

Latihan 2 dari materi Actions Svelte di Svelte — praktek dengan editor kode interaktif, test case otomatis, dan hint terpandu. Langsung jalan di browser.

Kode awalnya cuma berisi komentar TODO.

  1. Di <script>, buat action tooltip(node, text). Isinya node.setAttribute('title', text).
  2. Kembalikan objek berisi update(newText), yang memanggil node.setAttribute('title', newText), dan destroy(), yang memanggil node.removeAttribute('title').
  3. Di bawah script, buat tombol yang memakai action itu dengan teks Ini tooltip: <button use:tooltip={'Ini tooltip'}>Hover saya</button>.

Yang dicek:

Hint