Skip to content

Instantly share code, notes, and snippets.

@siarhei-zharnasek
Created May 15, 2018 11:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save siarhei-zharnasek/5221b5f0e5ccb2ed76db2a1b67b2d3ff to your computer and use it in GitHub Desktop.
Save siarhei-zharnasek/5221b5f0e5ccb2ed76db2a1b67b2d3ff 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