fabbe680

Untitled

Mar 15th, 2021
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.73 KB | None | 0 0
  1. class Timer {
  2. constructor() {
  3. var time = 0;
  4. stop = true;
  5. setInterval(update,1000);
  6. }
  7. setStop(bool) { this.stop = bool; console.log(this.stop); }
  8. getStop() { return this.stop; }
  9. setTime(t) { this.time = t; }
  10. getTime() { return this.time; }
  11. }
  12.  
  13. class Excerpt {
  14. constructor(a,b,c) {
  15. this.text = a;
  16. this.title = b;
  17. this.author = c;
  18. }
  19. }
  20.  
  21. const input = document.getElementById('input');
  22. const hidden = document.getElementById('hidden');
  23. const btn = document.getElementById('button');
  24. const clock = document.getElementById('timer');
  25. const gross = document.getElementById('gross');
  26. const net = document.getElementById('net');
  27. const acc = document.getElementById('acc');
  28. const err = document.getElementById('err');
  29. const exArray = new Array();
  30. const timer = new Timer();
  31.  
  32. var i = 1;
  33. var entries = 0;
  34. var right = 0, wrong = 0;
  35. var inText = '';
  36. var grossWPM = 0;
  37. var netWPM = 0;
  38. var accuracy = 0;
  39. var txtPara;
  40. var charIn = '';
  41.  
  42. const neuro = 'Cyberspace. A consensual hallucination experienced daily by billions of legitimate operators, in every nation, by children being taught mathematical concepts... A graphic representation of data abstracted from banks of every computer in the human system. Unthinkable complexity. Lines of light ranged in the nonspace of the mind, clusters and constellations of data. Like city lights, receding.';
  43.  
  44. function txtIn() {
  45. var str = this.value;
  46. charIn = str.slice(-1);
  47.  
  48. inText += charIn;
  49. entries += 1;
  50. onType();
  51.  
  52. timer.setStop(false);
  53.  
  54. //Clear text field
  55. if ( str.slice(-1) == ' ' ) {
  56. this.value = '';
  57. }
  58. }
  59.  
  60. function clkBtn() {
  61. var play = 'img/play.png', stop = 'img/stop.png';
  62.  
  63. //Change image when button is clicked
  64. if ( this.getAttribute('src') == play ) {
  65. this.src = stop;
  66. timer.setStop(true);
  67. } else if ( this.getAttribute('src') == stop ) {
  68. this.src = play;
  69. stop = false;
  70. timer.setStop(false);
  71. }
  72. }
  73.  
  74. function onType() {
  75. if ( !timer.getStop() ) {
  76. var holder = document.getElementById('holder');
  77. var i = inText.length - 1;
  78.  
  79.  
  80. //Create span element
  81. if ( inText.slice(-1) != neuro[i] ) {
  82. var wc = document.createElement('span');
  83. wc.textContent = neuro[i];
  84. wc.setAttribute('class','wrongc');
  85. holder.insertBefore(wc,hidden)
  86. hidden.innerHTML = neuro.slice(i+1);
  87. wrong += 1;
  88. i++;
  89. } else {
  90. var rc = document.createElement('span');
  91. rc.textContent = neuro[i];
  92. rc.setAttribute('class','rightc');
  93. holder.insertBefore(rc,hidden)
  94. hidden.innerHTML
  95. hidden.innerHTML = neuro.slice(i+1);
  96. right += 1;
  97. i++;
  98. }
  99.  
  100. //Update Stats
  101. accuracy = ( right / ( right + wrong ) ) * 100;
  102.  
  103. acc.innerHTML = 'Accuracy: ' + accuracy.toFixed(0) + '%';
  104. err.innerHTML = 'Errors: ' + wrong;
  105. }
  106. }
  107.  
  108. function update() {
  109. if ( timer.getTime() != 60 && !timer.getStop() ) {
  110. timer.setTime(timer.getTime += 1)
  111. if ( timer.getTime() <= 60 ) {
  112. clock.innerHTML = 60 - timer.getTime();
  113. }
  114.  
  115. //Update Stats
  116. grossWPM = ( entries / 5 ) / ( time / 60 );
  117. netWPM = grossWPM - ( wrong / ( time / 60 ) );
  118.  
  119. gross.innerHTML = 'Gross WPM: ' + grossWPM.toFixed(0);
  120. net.innerHTML = 'Net WPM: ' + netWPM.toFixed(0);
  121. }
  122. }
  123.  
  124. function init() {
  125. input.addEventListener('input',txtIn);
  126. btn.addEventListener('click',clkBtn);
  127.  
  128. hidden.innerHTML = neuro;
  129. }
  130.  
  131. window.addEventListener('load',init);
Advertisement
Add Comment
Please, Sign In to add comment