Advertisement
GalinaKG

Untitled

Mar 18th, 2022
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. function highJump (input) {
  2. let index = 0;
  3. let wantedHigh = Number(input[index]);
  4. index++;
  5. let high = wantedHigh - 30;
  6. let isSuccess = false;
  7. let countJumps = 0;
  8. let lastHigh = 0;
  9.  
  10. for (let i = high; i <= wantedHigh; i+= 5) {
  11. lastHigh = i;
  12. let unsuccessJumps = 0;
  13. for (let j = 1; j <= 3; j++) {
  14. let jump = Number(input[index]);
  15. index++
  16. if (jump > i) {
  17. isSuccess = true;
  18. countJumps++;
  19. break;
  20. } else {
  21. unsuccessJumps++;
  22. countJumps++;
  23. if (unsuccessJumps === 3) {
  24. isSuccess = false;
  25. break;
  26. }
  27. }
  28.  
  29. }
  30. if (isSuccess === false) {
  31. break;
  32. }
  33.  
  34. }
  35.  
  36. if (isSuccess === false) {
  37. console.log(`Tihomir failed at ${lastHigh}cm after ${countJumps} jumps.`);
  38. } else {
  39. console.log(`Tihomir succeeded, he jumped over ${lastHigh}cm after ${countJumps} jumps.`);
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement