Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function highJump(input){
- let index = 0;
- let targetHeight = Number(input[0]);
- index++;
- let initialHeight = targetHeight - 30;
- let attemptsCount = 0;
- let attemptsFailed = 0;
- let command = input[index];
- index++;
- while( command <= targetHeight || initialHeight != targetHeight){
- let currHight = Number(command);
- if(currHight > initialHeight){
- initialHeight += 5;
- attemptsFailed = 0;
- }else{
- attemptsFailed++;
- }
- attemptsCount++;
- if(attemptsFailed === 3){
- console.log(`Tihomir failed at ${initialHeight}cm after ${attemptsCount} jumps.`);
- break;
- }
- command = input[index];
- index++;
- }
- if(command > targetHeight){
- attemptsCount++;
- console.log(`Tihomir succeeded, he jumped over ${targetHeight}cm after ${attemptsCount} jumps.`);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement