Created
June 15, 2015 06:11
-
-
Save alison-mk/31677e708613dc8ebd28 to your computer and use it in GitHub Desktop.
Create an Endpoint
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
// 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