access hacker news json firebase api via jquery

Just a getJSON JQuery Request that will console log all of the hacker news top stories using the firebase api

$.getJSON('https://hacker-news.firebaseio.com/v0/topstories.json', function(json) {
var requests = [];

for (var i = 0; i < 10; i++) {
  requests.push($.getJSON('https://hacker-news.firebaseio.com/v0/item/' + json[i] + '.json'));
}

$.when.apply($, requests).done(function() {
  var results = [].slice.call(arguments);
  var list = results.map(function(arr) {
    return '<li><a href="' + arr[0].url + '">' + arr[0].title + '</a></li>';
  });
  var convoText = '<ol>' + list.join('') + '</ol>';
  console.log(convoText);
});
});

Demo

Other Items in js
Page Views

This page has been viewed 54 times.

Search Code
Search Code by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code snippits here, mostly for my reference. Also if i find a good site, i usually add it here.

❤👩‍💻🕹