Created
March 17, 2017 18:29
-
-
Save mariusz-blaszczak/f52b8bd9c8f588a285ae9de80ca6843b to your computer and use it in GitHub Desktop.
Another example from https://scotch.io/tutorials/javascript-promises-for-dummies
This file contains 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
const sumNumbersWithApi = (a, b) => { | |
const url = `https://stark-escarpment-75299.herokuapp.com/?a=${a}&b=${b}`; | |
return fetch(url) | |
.then(response => response.json()) | |
.then(response => response['response']) | |
.then(response => parseInt(response)) | |
.catch((error) => { | |
console.log("there was error:", error.message); | |
}); | |
}; | |
const putInConsole = (response) => { | |
console.log(response) | |
}; | |
sumNumbersWithApi(1,2) | |
.then(response => sumNumbersWithApi(3, response)) | |
.then(response => sumNumbersWithApi(3, response)) | |
.then(response => sumNumbersWithApi(3, response)) | |
.then(putInConsole); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment