Last active
June 1, 2018 09:47
-
-
Save dannycroft/54c3a5501c7d1e3aa5e155536642f363 to your computer and use it in GitHub Desktop.
Simple challenge to collect and parse users
This file contains hidden or 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
/* ----------------------------------------------------------------------------- | |
Complete the following tasks using only browser based APIs. Update | |
the supplied "getUsers()" function to achieve the following: | |
- Make a request to the API_URL (see below) | |
- Return a Promise | |
- Parse each of the returned results to match the example below: | |
[ | |
{ | |
name: 'Jane Doe', | |
age: 69, | |
email: '[email protected]' | |
},{ | |
... | |
} | |
] | |
Notes: Please return an array of objects. Each object should contain | |
the following: name, age and email. Running the assertions below will | |
help you return the correct results | |
----------------------------------------------------------------------------- */ | |
const API_URL = 'https://randomuser.me/api/?results=10'; | |
function getUsers() {} | |
/* ------------------ TEST ASSERTIONS - PLEASE DO NOT EDIT ------------------ */ | |
try { | |
getUsers() | |
.then(users => { | |
console.assert(users.length === 10, 'expected user array to have a length of 10'); | |
users.forEach(user => { | |
console.assert(user.hasOwnProperty('name'), `expected user to have a name`); | |
console.assert(user.hasOwnProperty('email'), `expected user to have an email`); | |
console.assert(user.hasOwnProperty('age'), `expected user to have an age`); | |
}); | |
console.log(`Current users -> `, users); | |
}) | |
.catch(err => console.error(`Test failure -> `, err)); | |
} catch (err) { | |
console.error(`Test failure -> `, err); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment