JavaScript Simplified / Chapter 107 Exercises

  • Index of exercises
  • Email me

1

2

3

4

5

6

7

8

9

10

Congratulations. You've aced all the exercises for this chapter.


To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to CodePen.


Are you ready to rate JavaScript Simplified? on Amazon?


Rate it on Amazon.

0,1,2,3,4,5,6,7,8,9

0

0

0

0

The name of the promise is prom. Fill in the blank. __________________________________________________
  let request = new XMLHttpRequest();
  request.open('GET', "slow-loris.html");
  request.onload = function() {
    if (request.status == 200) {
      resolve(request.response);
    } else {
      reject("File not Found");
    }
  };
  request.send();
});
const prom = new Promise(function(resolve, reject) { constprom=newPromise\(function\(resolve,reject\){
Fill in the blank. const prom = new Promise(function(resolve, reject) {
const prom = new Promise(function(resolve, reject) {
  let request = new XMLHttpRequest();
  request.open('GET', "slow-loris.html");
  _____________________________
    if (request.status == 200) {
      resolve(request.response);
    } else {
      reject("File not Found");
    }
  };
  request.send();
});
request.onload = function() { request\.onload=function\(\){
Fill in the blank. const prom = new Promise(function(resolve, reject) {
const prom = new Promise(function(resolve, reject) {
  let request = new XMLHttpRequest();
  request.open('GET', "slow-loris.html");
  request.onload = function() {
    ___________________________
      resolve(request.response);
    } else {
      reject("File not Found");
    }
  };
  request.send();
});
if (request.status == 200) { if\(request\.status==200\){
Fill in the blank. const prom = new Promise(function(resolve, reject) {
  let request = new XMLHttpRequest();
  request.open('GET', "slow-loris.html");
  request.onload = function() {
    if (request.status == 200) {
      _________________
    } else {
      reject("File not Found");
    }
    };
  request.send();
});
resolve(request.response); resolve\(request\.response\);
Fill in the blank. Make up the error text. const prom = new Promise(function(resolve, reject) {
  let request = new XMLHttpRequest();
  request.open('GET', "slow-loris.html");
  request.onload = function() {
    if (request.status == 200) {
      resolve(request.response);
    } else {
      ________________
    }
  };
  request.send();
});
reject("File not Found"); reject\(•.*•\);
Fill in the blank. _________________________________
  display(fileContent);
}).catch(function(errorText) {
  display(errorText);
});
prom.then(function(fileContent) { prom\.then\(function\(fileContent\){
Fill in the blank. prom.then(function(fileContent) {
  display(fileContent);
_________________________________
  display(errorText);
});
}).catch(function(errorText) { }\)\.catch\(function\(errorText\){
Fill in the blank. The function that's being called is display() prom.then(function(fileContent) {
  display(fileContent);
}).catch(function(errorText) {
  ________________
});
display(errorText); display\(errorText\);
  1. Replace the asterisks with code.
  2. Click the Result button (or, after revising, don't click, just wait).
  3. If you've coded correctly, the error text will appear in the Result panel.
  4. For help with this code, see Chapter 107 in the book.
  1. Code the second part of the promise.
  2. Click the Result button (or, after revising, don't click, just wait).
  3. If you've coded correctly, the error text will appear in the Result panel.
  4. For help with this code, see Chapter 107 in the book.