Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Weichu debug solution
* This file represents a simple application where we make 10 api requests to get
* 10 random words back and then append them based on the index of the word at the time the request was made
* There are many things wrong with this file, but when all are fixed the application should log out the list of words (generator.result)
var TOTAL_WORDS = 10;
var resultDiv = document.getElementById('result');
resultDiv.innerHTML = "Result pending..."
// params: times, how many times you want it get generated
// return: Array of generated words
function WordGenerator(times) {
var promiseList = [];
for (var i = 0; i < times; i++) {
.then((response) => {
return response.json();
}).then((jsonData) => {
return jsonData.word;
return Promise.all(promiseList)
.then(values => {
// console.log('promiseall', values);
return values;
function run() {
// call WordGenerator
WordGenerator(3).then((res)=> console.log('random', res));
// style it ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.