0
good night!
Can anyone tell me how to return the object using a type invocation:
book (booklet 1);
function book(bookName) {
var obj = {
livro1: {
quantidadePaginas: 300,
autor: "Jorge",
editora: "Atlas"
},
livro2: {
quantidadePaginas: 200,
autor: "Paulo",
editora: "Cia dos Livros"
},
livro3: {
quantidadePaginas: 150,
autor: "Pedro",
editora: "Bartolomeu"
}
};
if (!bookName) {
return obj;
};
return obj.bookName;
};
When I try to return this way, it appears that book1 is not set.
Where my thinking is wrong?
What I need to change in the function so I can return the value of object x (livrox) using the book (livrox invocation)?
Even replacing Return obj.bookName with Return obj[bookName], and invoking book(book1); it still says book1 is not set...
– Rodolpho Bravo