From bccd35b40d0ef007a997bc406232731af50fcbfd Mon Sep 17 00:00:00 2001 From: "aidwiz@yahoo.com" Date: Wed, 2 Oct 2019 19:50:55 +0800 Subject: [PATCH] done getTheTitles --- getTheTitles/getTheTitles.js | 10 +++++++++- getTheTitles/test.html | 13 +++++++++++++ getTheTitles/test.js | 26 ++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) create mode 100644 getTheTitles/test.html create mode 100644 getTheTitles/test.js diff --git a/getTheTitles/getTheTitles.js b/getTheTitles/getTheTitles.js index 2b52aa0..b7b8107 100644 --- a/getTheTitles/getTheTitles.js +++ b/getTheTitles/getTheTitles.js @@ -1,5 +1,13 @@ -const getTheTitles = function() { +const getTheTitles = function(books) { + + let titleArray = []; + for (i = 0; i < books.length; i++) { + // console.log(books[i].title); + titleArray.push(books[i].title); + } + console.log(titleArray); + return titleArray; } module.exports = getTheTitles; diff --git a/getTheTitles/test.html b/getTheTitles/test.html new file mode 100644 index 0000000..0e165d3 --- /dev/null +++ b/getTheTitles/test.html @@ -0,0 +1,13 @@ + + + + + + + Document + + + + + + \ No newline at end of file diff --git a/getTheTitles/test.js b/getTheTitles/test.js new file mode 100644 index 0000000..eeb8b03 --- /dev/null +++ b/getTheTitles/test.js @@ -0,0 +1,26 @@ +function getTheTitles(books) { + + let titleArray = []; + + for (i = 0; i < books.length; i++) { + // console.log(books[i].title); + titleArray.push(books[i].title); + } + + console.log(titleArray); +} + +//given data +const books = [ + { + title: "Book", + author: "Name" + }, + { + title: "Book2", + author: "Name2" + } +]; + +getTheTitles(books); +