nraynes / the-drinks-on-me

0 stars 1 forks source link

Cocktail DB API drink IDs are not in sequential order #2

Open JoVasquez84 opened 3 years ago

JoVasquez84 commented 3 years ago

API Used: www.thecocktaildb.com/api/json/v1/1/lookup.php?i=

Issue: The ID number for each cocktail is not stored in a sequential manner in the API. In order to generate 24 random cocktails, we attempted a random number generator in order to send a fetch request to return a random drink based on id but since the ids are not sequential, then there was no guarantee the random number generator would send a number which would fit within a valid range for API Ids. To get around this issue, we used the following API endpoint: www.thecocktaildb.com/api/json/v1/1/random.php

mojo9492 commented 3 years ago

Is it possible to implement an if check where if (randomgeneratedNumber > databaseArray.length) { // regenerate the number or make a ceiling value }

Could adding a ceiling to the random number generator help keep it within range?