Advertisement
Guest User

DankCodeJunk

a guest
Nov 11th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.17 KB | None | 0 0
  1. <div class="page-width">
  2. <h1 class="small--text-center">{{ page.title }}</h1>
  3. <div class="content-block">
  4. <div class="rte rte--indented-images">
  5. {{ page.content }}
  6.  
  7. <h3 id="test">IBO Speed</h3>
  8. <h5>(feet per second)</h5>
  9. <input type="text" id="ibospeed" />
  10. <h3>Draw Weight</h3>
  11. <h5>(pounds)</h5>
  12. <input type="text" id="drawweight" />
  13. <h3>Draw Length</h3>
  14. <h5>(inches)</h5>
  15. <input type="text" id="drawlength" />
  16. <h3>Arrow Weight</h3>
  17. <h5>(grains)</h5>
  18. <input type="text" id="arrowweight" />
  19. <br><br>
  20. <button onclick="calc()">Calculate</button>
  21.  
  22. <h2>Calculated Arrow Speed</h2>
  23. <label id="result">Calculation here.</label>
  24.  
  25. </div>
  26. </div>
  27.  
  28. {% section 'featured-products-subsection' %}
  29. </div>
  30.  
  31. <script>
  32. function calc() {
  33.  
  34.  
  35. //Bring the values from the text boxes into variables.
  36. //The parseFloat will take the first number/decimal it finds as long as
  37. //the variable starts with a numeric character.
  38. var ibo = parseFloat(document.getElementById("ibospeed").value);
  39. var drw = parseFloat(document.getElementById("drawweight").value);
  40. var drl = parseFloat(document.getElementById("drawlength").value);
  41. var arw = parseFloat(document.getElementById("ibospeed").value);
  42. var flag = false;
  43.  
  44. //If any of the text boxes weren't a valid number, then the variables value
  45. //would become NaN. If there is a number greater than 1 in an if() statement
  46. //it will evaluate to true, and if it is NaN its false. We want to change the flag
  47. //if it is NaN though so the value checked is flipped with !.
  48. if(!ibo) {
  49. flag = true;
  50. }
  51. else if(!drw) {
  52. flag = true;
  53. }
  54. else if(!drl) {
  55. flag = true;
  56. }
  57. else if(!arw) {
  58. flag = true;
  59. }
  60.  
  61. //If the flag was set, display a message and hope that the user fixes it.
  62. //Otherwise, start performing calculations.
  63. if(flag) {
  64. document.getElementById("result").innerHTML = "Please make sure everything is a number, then hit the calculate again!";
  65. }
  66. else {
  67.  
  68. var dla = 0;
  69. var dwa = 0;
  70. var kezero = 0;
  71. var awdw = (arw/drw).toPrecision(10);
  72. var keone = 0;
  73.  
  74. //dla
  75. switch(drl) {
  76. //case ((drl >= 18) && (drl <= 28)):
  77. case 1:
  78. dla = (-8 * drl) + 244;
  79. break;
  80. case (drl <= 32):
  81. dla = (-10 * drl) + 300;
  82. break;
  83. default:
  84. document.getElementById("result").innerHTML = "Sorry, Draw Length needs to be between 18 and 32 for the calculation to work.";
  85. return;
  86. };
  87.  
  88. //dwa
  89. switch(drw) {
  90. case ((drw >= 14.75) && (drw <= 50)):
  91. dwa = ((-28.2 * drw) / 35.25) + (2079.75 / 35.25);
  92. break;
  93. case (drw <= 60):
  94. dwa = ((-9 * drw) / 10) + 64;
  95. break;
  96. case (drw <= 70):
  97. dwa = (-drw) + 70;
  98. break;
  99. case (drw <= 80):
  100. dwa = ((-9 * drw) / 10) + 63;
  101. break;
  102. case (drw <= 90):
  103. dwa = ((-8 * drw) / 10) + 55;
  104. break;
  105. default:
  106. document.getElementById("result").innerHTML = "Sorry, Draw Weight needs to be between 14.75 and 90 for the calculation to work.";
  107. return;
  108. };
  109.  
  110. //ke0
  111. kezero = (drw * 5) * (((ibo-dla-dwa)^2)/450800).toPrecision(10);
  112.  
  113. //ke1
  114. switch(awdw) {
  115. case ((awdw >= 4) && (awdw <= 5.9)):
  116. keone = kezero + 0;
  117. break;
  118. case (awdw <= 12):
  119. keone = kezero + ((5.4 * awdw) / 6) - (31.86 / 6);
  120. break;
  121. case (awdw <= 18):
  122. keone = kezero + ((2.2 * awdw) / 5.9) + (6.066 / 5.9);
  123. break;
  124. case (awdw <= 68):
  125. keone = kezero + 0;
  126. break;
  127. default:
  128. document.getElementById("result").innerHTML = "Sorry, something went wrong with the calculation, please contact Robert!";
  129. return;
  130.  
  131. }
  132.  
  133. document.getElementById("result").innerHTML = keone;
  134. }
  135.  
  136. };
  137. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement