Last active
August 20, 2019 15:46
-
-
Save xniro/bc6e2d535ee36a86336d3ee5e71ee657 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This is the solution I found for the streak of launches | |
const baseLaunchURL = "https://api.spacexdata.com/v3/launches/"; | |
// Schedule API | |
// Get All Launch Data | |
const getAllLaunchInformation = () => { | |
return fetch(baseLaunchURL) | |
.then(response => response.json()) | |
} | |
// Data | |
getAllLaunchInformation().then((launchData) => { | |
let successfullAttempts; | |
let failedAttempts; | |
launchData.map((launch) => { | |
if(launch.launch_success === true ) { | |
successfullAttempts = launch.launch_success; | |
return console.log(successfullAttempts + " - Success Streak") | |
} else if (launch.launch_success === false) { | |
failedAttempts = launch.launch_success; | |
return console.log(failedAttempts); | |
} | |
}) | |
}); | |
// This counts the number of 'true' from the array and ends at the next false it sees | |
// The first 3 were failed launches, then they had a streak of 20, then failed 1, had a streak of 9, failed one again, | |
// then had another streak of 49 successful launches. | |
// This outputs | |
(20) true - Success Streak | |
(9) true - Success Streak | |
(49) true - Success Streak |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment