Advertisement
Guest User

High Jump

a guest
Feb 7th, 2020
937
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve(input){
  2.  
  3.     let jumpHeightWanted = +input.shift();
  4.     let jumpHeight = +input.shift();
  5.     let firstJump = jumpHeightWanted - 30;
  6.     let numJumps = 0;
  7.     let failJumps = 0;
  8.  
  9.     while(jumpHeightWanted>=jumpHeight){
  10.          
  11.         if(firstJump<jumpHeight){
  12.             firstJump += 5;
  13.             failJumps = 0;
  14.             numJumps++;
  15.  
  16.         }else if(firstJump>=jumpHeight){
  17.            
  18.            
  19.             failJumps ++;
  20.             numJumps++;
  21.             if(failJumps / 3 == 1){
  22.               console.log(`Tihomir failed at ${firstJump}cm after ${numJumps} jumps.`)
  23.                 return;
  24.             }
  25.            
  26.         }
  27.  
  28.      
  29.        
  30.  
  31.  
  32.  
  33.        jumpHeight = input.shift();
  34.        
  35.      
  36.     }
  37.  
  38.     if(jumpHeightWanted<jumpHeight){
  39.         numJumps++;
  40.         console.log(`Tihomir succeeded, he jumped over ${jumpHeightWanted}cm after ${numJumps} jumps.`);
  41.     }
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement