jank.js 645 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. let interval = null;
  2. let result = null;
  3. function initJank() {
  4. const button = document.getElementById( 'button' );
  5. button.addEventListener( 'click', function () {
  6. if ( interval === null ) {
  7. interval = setInterval( jank, 1000 / 60 );
  8. button.textContent = 'STOP JANK';
  9. } else {
  10. clearInterval( interval );
  11. interval = null;
  12. button.textContent = 'START JANK';
  13. result.textContent = '';
  14. }
  15. } );
  16. result = document.getElementById( 'result' );
  17. }
  18. function jank() {
  19. let number = 0;
  20. for ( let i = 0; i < 10000000; i ++ ) {
  21. number += Math.random();
  22. }
  23. result.textContent = number;
  24. }
  25. export default initJank;