If I understand correctly, when doing GetBooking(pages)
you expect to get in return Booking.Title[0].pages
, meaning GetBooking()
function is supposed to be like a middleman to decide which property you want to get from Booking.Title[0]
.
If I'm correct, then you almost had it right. What will happen in your code is, for example if number
was 7, it would look for a property named 7
inside Booking.Title[0]
.
What you really want to do is this: return Booking.Title[0][parameter]
, and parameter
has to be a string value representing the property you're looking for, meaning you also need to change the rest of the code which would ultimately look like this:
GetBooking = function (parameter) {
return Booking.Title[0][parameter];
}
GetPages = function () {
return GetBooking("pages") ;
}
GetNumber = function () {
return GetBooking("number") ;
}
This will take the string in parameter
and look for a property that matches that string inside Booking.Title[0]
, and return its value.