選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

37 行
978B

  1. ---
  2. example:
  3. title: Timer Button
  4. instructions: Add an event listener to toggle the `#timer-button` between **start**
  5. and **stop** states.
  6. hint: Use the button's `value` to track whether the next action should be `'start'`
  7. or `'stop'`.
  8. solution:
  9. js: |+2
  10. const timerBtn = document.getElementById('timer-button')
  11. timerBtn.addEventListener('click', ev => {
  12. const btn = ev.currentTarget
  13. const action = btn.value
  14. console.log(action)
  15. if (action === 'start') {
  16. btn.value = 'stop'
  17. btn.textContent = 'Stop Timer'
  18. } else if (action === 'stop') {
  19. btn.value = 'start'
  20. btn.textContent = 'Start Timer'
  21. }
  22. })
  23. css: ~
  24. output: js4shiny::html_document_plain
  25. ---
  26. <div class="controls">
  27. <button id="timer-button" value="start">Start Timer</button>
  28. </div>
  29. <div id="timer">
  30. <span id="timer-minutes">00</span>:<span id="timer-seconds">00</span>
  31. </div>