Skip to content

Instantly share code, notes, and snippets.

@alison-mk
Created June 15, 2015 06:11
Show Gist options
  • Save alison-mk/31677e708613dc8ebd28 to your computer and use it in GitHub Desktop.
Save alison-mk/31677e708613dc8ebd28 to your computer and use it in GitHub Desktop.
Create an Endpoint
// Objective: create an endpoint using app.get that sends a JSON object
// Set /dinosaurs as endpoint
app.get("/dinosaurs", function (req, res){
// Assign dinosaur as JSON object, pull a random dinosaur out of array of dinos
res.json({dinosaur: array[randomNumber]});
});
// Array of dinosaurs
var array = [ "Stegosaurus", "Tyrranosaurus", "Velociraptor", "Triceratops"];
// Find length of dino array
var limit = array.length;
// Get random number that is less than length of dino array
var randomNumber = Math.floor(Math.random() * limit);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment