Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

40 lines
1.0KB

  1. ---
  2. example:
  3. title: Compare Time
  4. instructions: Find the number of minutes and seconds between `then` and `now`
  5. runtime: repl_js
  6. initial:
  7. js: |+2
  8. const then = new Date()
  9. // or enter a time stamp for a not too distant date & time
  10. // const then = new Date("2019-12-02 12:24:00")
  11. setTimeout(() => {
  12. const now = new Date()
  13. console.log({then, now, diff: now - then})
  14. }, 2123)
  15. solution:
  16. js: |+2
  17. const then = new Date()
  18. // const then = new Date("2019-12-02 12:24:00")
  19. setTimeout(() => {
  20. const now = new Date()
  21. let seconds = Math.floor((now - then) / 1000)
  22. let minutes = 0
  23. if (seconds >= 60) {
  24. minutes = Math.floor(seconds / 60)
  25. seconds = seconds - minutes * 60
  26. }
  27. minutes = (minutes < 10 ? '0' : '') + minutes
  28. seconds = (seconds < 10 ? '0' : '') + seconds
  29. console.log({seconds, minutes})
  30. }, 2123)
  31. css: ~
  32. output: js4shiny::html_document_plain
  33. ---