...

/

Exercise on ES6 Promises

Exercise on ES6 Promises

In the following exercises, we will practice promises by handling success and failure in data retrieval.

We'll cover the following...

Exercise 1:

List the names of the users retrieved via this endpoint using ajax.

Make sure you don’t use jQuery, and you use promises to handle success and failure. Place the names in the div below, having a class .js-names, and separate them with a simple comma. Make sure you do not use jQuery to access or modify the content of the below div.

<div style="border:1px black solid;" 
     class="js-names"></div>

Solution:

If you want to test the solution, you can simply prepend the test div to the beginning of the body:

document.body.innerHTML = `
<div style="border:1px black solid;"
class="js-names"></div>` +
document.body.innerHTML;

Notice the template literal that enables us to add new lines without closing the literal.

I assume that at least half of my readers came up with a solution that uses jQuery.

jQuery lowered the entry barriers to frontend development, and we can be grateful for it. However, jQuery has done its job, and we don’t necessarily need it now that ES6 is expressive enough.

This solution will work without jQuery. ...