Advertisement
svephoto

High Jump [JavaScript]

Jan 16th, 2022
1,392
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function highJump(input) {
  2.     let neededHeight = Number(input[0]);
  3.    
  4.     let index = 1;
  5.  
  6.     let startingHeight = neededHeight - 30;
  7.     let attempts = 0;
  8.     let jumps = 0;
  9.    
  10.     while (startingHeight <= neededHeight) {
  11.         let tempResult = Number(input[index]);
  12.            
  13.         if (tempResult > startingHeight) {
  14.             startingHeight += 5;
  15.             attempts = 0;
  16.         } else {
  17.             attempts++;
  18.         }
  19.            
  20.         jumps++;
  21.  
  22.         if (attempts === 3) {
  23.             break;
  24.         }
  25.  
  26.         index++;
  27.     }
  28.  
  29.     if (attempts === 3) {
  30.         console.log(`Tihomir failed at ${startingHeight}cm after ${jumps} jumps.`);
  31.     } else {
  32.         console.log(`Tihomir succeeded, he jumped over ${neededHeight}cm after ${jumps} jumps.`);
  33.     }
  34. }
  35.  
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement