1

So the first part of the instruction said make a get request for a turtles route, and send a JS object of the turtles and their colors, which I did here:

app.get('/turtles', function(req, res) {

data = {
    Raphael: "Red",
    Leonardo: "Blue",
    Donatello: "Black",
    Michaelangelo: "Orange"
}

console.log(data);
}); 

But the second part says make a get request for a 'turtles/:id' route that will send a string with the param: "The turtle you want to see is ------------" I'm not sure what I have to do.

app.get('/turtles/:id', function(req, res) {

data = {
   Raphael: "Red",
   Leonardo: "Blue",
   Donatello: "Black",
   Michaelangelo: "Orange"
  }

What would I have to console log here? req.params.id?

user5539793
  • 81
  • 1
  • 2
  • Possible duplicate of [how to get url parameter in express node js](http://stackoverflow.com/questions/20089582/how-to-get-url-parameter-in-express-node-js) – 0x9BD0 Nov 12 '15 at 05:36

1 Answers1

0

I'm assuming you want it to output the color of the selected turtle. So you might make a request for /turtles/Raphael. At this point, you'll need to retrieve the color of that turtle, and then output that color. So you might do something like:

app.get('/turtles/:id', function(req, res){
    var turtle = req.params.id;

    data = {
        Raphael: "Red",
        Leonardo: "Blue",
        Donatello: "Black",
        Michaelangelo: "Orange"
    }

    console.log("The turtle you want to see is " + data[turtle]);
});
jordan
  • 9,570
  • 9
  • 43
  • 78
  • `data.turtle` won't work since *turtle* is not defined as a variable in the object. However, `data[turtle]` will work. – Andrius Nov 12 '15 at 07:38