Advertisement
ggeorgiev88

30/100 judge???

Dec 15th, 2022
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. function highJump(input) {
  2.  
  3. let goalJump = Number(input[0]);
  4. let index = 1
  5. let currentJump = Number(input[index]);
  6. let positiveCounter = 0;
  7. let negativeCounter = 0
  8. let currentGoalJump = goalJump - 30;
  9. let totalJumpCounter = 0
  10.  
  11. while (currentJump < goalJump) {
  12. totalJumpCounter++
  13. if (currentJump > currentGoalJump) {
  14. positiveCounter++;
  15. currentGoalJump += 5;
  16. negativeCounter = 0;
  17.  
  18.  
  19. } else if (currentJump <= currentGoalJump) {
  20. negativeCounter++
  21. }
  22. index++;
  23. currentJump = Number(input[index]);
  24.  
  25. if (negativeCounter === 3) {
  26. console.log(`Tihomir failed at ${currentGoalJump}cm after ${totalJumpCounter} jumps.`); return;
  27. }
  28.  
  29. }
  30. totalJumpCounter++
  31.  
  32. console.log(`Tihomir succeeded, he jumped over ${goalJump}cm after ${totalJumpCounter} jumps.`);
  33.  
  34.  
  35.  
  36.  
  37.  
  38. }
  39.  
  40. // highJump(["231"
  41. // , "205"
  42. // , "212"
  43. // , "213"
  44. // , "228"
  45. // , "229"
  46. // , "230"
  47. // , "235"
  48. // ]);
  49.  
  50. highJump(["250"
  51. ,"225"
  52. ,"224"
  53. ,"225"
  54. ,"228"
  55. ,"231"
  56. ,"235"
  57. ,"234"
  58. ,"235"]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement