Created
July 20, 2015 05:50
-
-
Save Restuta/1cfa4d20816a6fa864fc to your computer and use it in GitHub Desktop.
Get random Marvel character
This file contains 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
function getRandomBetween(min, max) { | |
return Math.floor(Math.random() * (max - min + 1)) + min; | |
} | |
var apiKey = 'apikey=ed23113a7ebab2304b0aad655ec41c6a'; | |
var totalCharacters = 1485; | |
var randomOffset = getRandomBetween(1, totalCharacters); | |
//var randomOffset = 1341; | |
$.get('http://gateway.marvel.com:80/v1/public/characters?limit=1&offset=' + randomOffset + '&' + apiKey) | |
.then(function(result) { | |
console.log(result); | |
var thumbnail = result.data.results[0].thumbnail.path + '/standard_fantastic' + '.' + result.data.results[0].thumbnail.extension; | |
console.log(thumbnail) | |
return result.data.results[0].resourceURI; | |
}) | |
.then(function(characterURI) { | |
return $.get(characterURI + '?' + apiKey) | |
}) | |
.then(function(result) { | |
console.log(result); | |
console.log(result.data.results[0].name); | |
var thumbnail = result.data.results[0].thumbnail.path + '/standard_fantastic' + '.' + result.data.results[0].thumbnail.extension; | |
console.log(thumbnail) | |
window.open(thumbnail, "Marvel", "width=300,height=300"); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment