From 29f2b1654108a22a27f213e4359950e449b2f9a3 Mon Sep 17 00:00:00 2001 From: shiowwj Date: Thu, 14 Mar 2019 18:29:26 +0800 Subject: [PATCH 1/3] Created and edited new html and js file part 1 -5. --- index.html | 11 ++++++ script.js | 107 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 index.html create mode 100644 script.js diff --git a/index.html b/index.html new file mode 100644 index 0000000..8fff9b4 --- /dev/null +++ b/index.html @@ -0,0 +1,11 @@ + + + + Google Shopping Functions + + +

Google Shopping Functions

+ + + + diff --git a/script.js b/script.js new file mode 100644 index 0000000..ba3ec6d --- /dev/null +++ b/script.js @@ -0,0 +1,107 @@ +console.log(products.items.length); + +// var prodItem = products.items; +// var brand = prodItem[i].product.brand; +// var title = products.items[i].product.title; +// var author = prodItem[i].product.author.name; +// var hasName = author.search("eBay"); +// var imgLink = prodItem[i].product.images[0].link; +// var condition = prodItem[i].product.condition; + + +/************************************/ +var counter =1; +var userInputBrand = "sony".toLowerCase(); +var userInputAuthor ="ebay".toLowerCase(); + +console.log(userInputBrand); +console.log(userInputAuthor); + + // 1.) getItems(objectData) +function getItems(input) { + + var prodItem = input.items; + return prodItem; + +} + + + +/************************************/ + +// ## 2.) getItemsByBrand(items, brand) +function getItemsByBrand(items, brand) { +var outDetails = []; + for (var i = 0; i < items.length; i++) { + if((items[i].product.brand).toLowerCase() == brand) { + // outDetails.push(counter++ + ")" + " " + "Model: " + items[i].product.title) + // console.log(counter++ + ")" + " " + "Model: " + items[i].product.title) + outDetails.push(items[i]); + } + } +return outDetails; +} + +/************************************/ + +//## 3.) getItemsByAuthor(items, author) +//if indexOf > 0 + +function getItemsByAuthor(items, author) { +var outAuthor = []; + for (var i = 0; i = 0) { + // outAuthor.push("Author: " + items[i].product.author.name + ", " + "Model: " + items[i].product.title); + outAuthor.push(items[i]); + } + } +return outAuthor; +} +// (counter++ + ")" + " " + "Model: " + items[i].product.title + ", " + "Author: " + items[i].product.author.name) +//to print stuff + +/************************************/ + +//## 4.) getAvailableProducts(items) +// products.items[1].product.inventories[0].availability + +function getAvailableProducts(items) { +var availableArr =[]; + for (var i = 0; i < items.length; i++) { + var n = items[i].product.inventories[0].availability.toLowerCase(); + if(n == "instock") { + // availableArr.push(items[i]); + availableArr.push(items[i]); + + } + } +return availableArr +} + + +// getItems(products); +// console.log(getItemsByBrand(getItems(products), userInputBrand)); +// console.log(getItemsByAuthor(getItems(products),userInputAuthor)); +// console.log(getAvailableProducts(getItems(products))); + +//5.1) sony items +console.log(getItemsByBrand(getItems(products), "sony")); + + // 5.2) Sony and available +console.log(getItemsByBrand(getAvailableProducts(getItems(products)), "sony")); + +// 5.3) available, author "adorama" +console.log(getAvailableProducts(getItemsByAuthor(getItems(products),"adorama"))); + +//5.4) nikon all and author ebay +console.log(getItemsByBrand(getItemsByAuthor(getItems(products),"ebay"), "nikon")); + +/* +5/ Use the functions you created in 1 - 4 to ouput (console.log) the following lists of items. + +* All items made by Sony. +* All items made by Sony that are available. +* All available items by the author "Adorama Camera" +* All items made by Nikon with the author eBay. +*/ From 0986af94c1a0e9d6e5622740eef132a63a053998 Mon Sep 17 00:00:00 2001 From: shiowwj Date: Thu, 14 Mar 2019 18:36:03 +0800 Subject: [PATCH 2/3] updated part 5 --- script.js | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/script.js b/script.js index ba3ec6d..2ce70d0 100644 --- a/script.js +++ b/script.js @@ -1,18 +1,8 @@ -console.log(products.items.length); - -// var prodItem = products.items; -// var brand = prodItem[i].product.brand; -// var title = products.items[i].product.title; -// var author = prodItem[i].product.author.name; -// var hasName = author.search("eBay"); -// var imgLink = prodItem[i].product.images[0].link; -// var condition = prodItem[i].product.condition; - - +//##1. /************************************/ var counter =1; var userInputBrand = "sony".toLowerCase(); -var userInputAuthor ="ebay".toLowerCase(); +var userInputAuthor ="adorama".toLowerCase(); console.log(userInputBrand); console.log(userInputAuthor); @@ -92,7 +82,8 @@ console.log(getItemsByBrand(getItems(products), "sony")); console.log(getItemsByBrand(getAvailableProducts(getItems(products)), "sony")); // 5.3) available, author "adorama" -console.log(getAvailableProducts(getItemsByAuthor(getItems(products),"adorama"))); +console.log(getItemsByAuthor(getItems(products),"adorama")); +// console.log(getAvailableProducts(getItemsByAuthor(getItems(products),"adorama"))); //5.4) nikon all and author ebay console.log(getItemsByBrand(getItemsByAuthor(getItems(products),"ebay"), "nikon")); @@ -105,3 +96,15 @@ console.log(getItemsByBrand(getItemsByAuthor(getItems(products),"ebay"), "nikon" * All available items by the author "Adorama Camera" * All items made by Nikon with the author eBay. */ + +// console.log(products.items.length); + +// var prodItem = products.items; +// var brand = prodItem[i].product.brand; +// var title = products.items[i].product.title; +// var author = prodItem[i].product.author.name; +// var hasName = author.search("eBay"); +// var imgLink = prodItem[i].product.images[0].link; +// var condition = prodItem[i].product.condition; + + From a7b762d21b093fe27816370822d5f55c03813e6b Mon Sep 17 00:00:00 2001 From: shiowwj Date: Fri, 15 Mar 2019 17:05:24 +0800 Subject: [PATCH 3/3] Added script file (script2.js). Calling of functions --- index.html | 1 + script2.js | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 script2.js diff --git a/index.html b/index.html index 8fff9b4..40ce467 100644 --- a/index.html +++ b/index.html @@ -7,5 +7,6 @@

Google Shopping Functions

+ diff --git a/script2.js b/script2.js new file mode 100644 index 0000000..5d93aec --- /dev/null +++ b/script2.js @@ -0,0 +1,12 @@ +//5.1) sony items +console.log(getItemsByBrand(itemsList, "sony")); + + // 5.2) Sony and available +console.log(getItemsByBrand(getAvailableProducts(itemsList), "sony")); + +// 5.3) available, author "adorama" +console.log(getItemsByAuthor((itemsList),"adorama")); +// console.log(getAvailableProducts(getItemsByAuthor(getItems(products),"adorama"))); + +//5.4) nikon all and author ebay +console.log(getItemsByBrand(getItemsByAuthor(itemsList,"ebay"), "nikon"));