Computer scienceProgramming languagesJavaScriptAdvanced featuresPromise

"then", "catch" and "finally" methods

Oops! We have a problem

Report a typo

Change the hasDownloaded function by using .then or .then and .catch and display the texts passed to the resolve and reject functions in the console as arguments.

Sample Input 1:

false

Sample Output 1:

Oops! An error occurs

Sample Input 2:

true

Sample Output 2:

Now you can watch the video!
Write a program in JavaScript
function hasDownloaded (value) {
const promise = new Promise(function(resolve, reject){
if (value === "true"){
resolve("Now you can watch the video!");
} else {
reject("Oops! An error occurs");
}
});

return promise
}
___

Create a free account to access the full topic