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

Claudia - Shopping Functions Assignment #78

Open
wants to merge 1 commit 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
11 changes: 11 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script src="products.js"></script>
<script src="js/google_shopping_functions.js"></script>
<script src="script.js"></script>
</body>
</html>
48 changes: 45 additions & 3 deletions js/google_shopping_functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,56 @@
* 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;
// }

//Deliverables 1
var getItems = function(objectData) {
return objectData.items
}

//Deliverables 2
var getItemsByBrand = function(items, brand) {
var brandResults = []
for (i=0; i<items.length;i++) {
if (items[i].product.brand === brand) {
brandResults.push(items[i]);
}
}
return brandResults;
}

//Deliverables 3
var getItemsByAuthor = function (items, author) {
var authorResults = []
for (j=0; j<items.length; j++) {
if (items[j].product.author.name.includes(author)) {
authorResults.push(items[j]);
}
}
return authorResults;
}

//Deliverables 4
var getAvailableProducts = function (items) {
var inStock = []
for (k=0; k<items.length;k++) {
for (l=0; l<items[k].product.inventories.length;l++) {
if (items[k].product.inventories[l].availability === "inStock") {
inStock.push(items[k]);
break;
}
}
}
return inStock;
}


/*
* Define and use your functions here
*/

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

37 changes: 37 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// console.log(products);
// console.log('Item Count: ' + getItemsCount(products));

// Deliverable 1
console.log("Item Array: ")
console.log(getItems(products));

// Deliverable 2
console.log("Array of items by Sony: ")
console.log(getItemsByBrand(getItems(products),"Sony"));

// Deliverable 3
console.log("Array of items by Target: ")
console.log(getItemsByAuthor(getItems(products),"Target"));

// Deliverable 4
console.log("Available products: ")
console.log(getAvailableProducts(getItems(products)));

// Deliverable 5
//
// All items made by Sony.
console.log("Array of items by Sony: ")
console.log(getItemsByBrand(getItems(products),"Sony"));

// All items made by Sony that are available.
console.log("Items made by Sony that are available: ")
console.log(getAvailableProducts(getItemsByBrand(getItems(products),"Sony")))

// All available items by the author "Adorama Camera"
console.log("Available items by Adorama Camera: ")
console.log(getAvailableProducts(getItemsByAuthor(getItems(products),"Adorama Camera")));

// All items made by Nikon with the author eBay.
console.log("Items made by Nikon with author eBay: ")
console.log(getItemsByBrand(getItemsByAuthor(getItems(products),"eBay"),"Nikon"));