Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Andrew - Slowly but surely #84

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="products.js"></script>
<script src="js/google_shopping_functions.js"></script>
<script src="script.js"></script>
</head>
<body>
<h1>Google-shopping-functions</h1>
</body>
</html>
68 changes: 64 additions & 4 deletions js/google_shopping_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,74 @@
* input: accepts full item data
* output: returns the length of the items array
*/
function getItemsCount(itemData) {
return itemData.items.length;
}
// function getItemsCount(itemData) {
// return itemData.items.length;
// }

/*
* Define and use your functions here
*/

function getItems(objectData){
console.log("Get items array");
return objectData.items;
}

function getItemsByBrand(array, brandName){
var brandArray = [];
for (var i = 0; i< array.length;i++ ){
if(array[i].product.brand == brandName){
brandArray.push(array[i]);
}else{
//do nothing;
}
}
console.log(brandArray);
return(brandArray);
}

function getItemsByAuthor(array, brandAuthor){
var authorArray = [];
for (var i = 0; i < array.length; i++){
if (array[i].product.author.name.includes(brandAuthor)){
authorArray.push(array[i]);
}
}
console.log(authorArray);
return(authorArray);
}

function getAvailableProducts(array, availableProducts){
var availableArray = [];
for (var i = 0; i < array.length; i++){
if (array[i].product.inventories[0].availability == availableProducts){
availableArray.push(array[i]);
}
}
console.log(availableArray);
return(availableArray);
}

// var availableArray = getAvailableProducts(availableArray, "inStock");
// // 4.) getAvailableProducts(items)
// // input: an array of items
// // returns: an array of items (that are available)

// function getAvailableProducts(items) {
// var newArray = [];
// for (i = 0; i < items.length; i++) {
// if (items[i].product.inventories[0].availability === "inStock") {
// newArray.push(items[i]);
// }
// }
// return newArray;
// }
// getAvailableProducts(productsArray);

// console.log(getAvailableProducts(productsArray));



// output item count using the getItemsCount function
console.log('Item Count: ' + getItemsCount(data));
// console.log('Item Count: ' + getItemsCount(data));

38 changes: 38 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Create a function called getItems that simply returns the items array from the google product object.
var productsArray = getItems(products);
console.log(productsArray);

var brandArray = getItemsByBrand(productsArray,"Sony");

var authorArray = getItemsByAuthor(productsArray, "eBay");

var availableArray = getAvailableProducts(productsArray, "inStock");

// console.log("Create a function called by getItemsByBrand")

// var itemsArray = getItemsByBrand(products.items);
// console.log(itemsArray);

// getItemsByBrand(items, brand)
// input: an array of items, a string of a brand to filter with
// returns: an array of items (of a specific brand)

// Create a function called getItemsByBrand that takes an item array returns a new array of all items of a specified brand.
// Test this function by searching for Sony, Canon, Nikon and Panasonic.

//Products > Items > Kind > Product > Brand

// function getItemsByBrand(items, brand){

// for (var i = 0; i < productsArray.items.kind.product.brand.length; i++){
// if (productsArray.items.kind.product.brand === items, brand){
// }
// }
// }