Skip to content

Instantly share code, notes, and snippets.

@jdmedeiros
Forked from siarhei-zharnasek/You should try JSON
Created March 8, 2020 18:24
Show Gist options
  • Save jdmedeiros/7f7116399ba72fa80e5b27d086e0d034 to your computer and use it in GitHub Desktop.
Save jdmedeiros/7f7116399ba72fa80e5b27d086e0d034 to your computer and use it in GitHub Desktop.
const URL = 'https://letsrevolutionizetesting.com/challenge.json';
function makeCall(url) {
return fetch(url).then(response => response.json());
}
function startChallenge(url) {
return makeCall(url)
.then(response => {
const {follow} = response;
if (follow) {
return startChallenge(follow.replace('challenge?', 'challenge.json?'));
}
return response;
});
}
startChallenge(URL)
.then(({message}) => console.log(`Result is: ${message}`))
.catch(error => console.log(`Error: ${error}`));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment