Advertisement
Guest User

Untitled

a guest
Dec 23rd, 2023
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function highJump(input){
  2.  
  3. let index = 0;
  4. let targetHeight = Number(input[0]);
  5. index++;
  6.  
  7. let initialHeight = targetHeight - 30;
  8. let attemptsCount = 0;
  9. let attemptsFailed = 0;
  10.  
  11. let command = input[index];
  12. index++;
  13.  
  14. while( command <= targetHeight || initialHeight != targetHeight){
  15.     let currHight = Number(command);
  16.    
  17.  
  18.    
  19.     if(currHight > initialHeight){
  20.         initialHeight += 5;
  21.         attemptsFailed = 0;
  22.     }else{
  23.         attemptsFailed++;
  24.         }
  25.  
  26.         attemptsCount++;
  27.  
  28.     if(attemptsFailed === 3){
  29.         console.log(`Tihomir failed at ${initialHeight}cm after ${attemptsCount} jumps.`);
  30.         break;
  31.     }
  32.  
  33.     command = input[index];
  34.     index++;
  35.     }
  36.  
  37. if(command > targetHeight){
  38.     attemptsCount++;
  39.     console.log(`Tihomir succeeded, he jumped over ${targetHeight}cm after ${attemptsCount} jumps.`);
  40. }
  41.  
  42.  
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement