forked from wdi-sea-01/google_products
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgoogle_shopping.js
More file actions
104 lines (75 loc) · 3.03 KB
/
Copy pathgoogle_shopping.js
File metadata and controls
104 lines (75 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
var data = require("./products.json")
// Write your solutions below
var itemsLength = data.items.length;
var shoppingProductCount = 0;
for (var i = 0; i < itemsLength ; i++) {
if (data.items[i].kind === "shopping#product") {
shoppingProductCount += 1;
};
}
console.log("There are " + shoppingProductCount + " items with the kind 'shopping#prodcut'");
console.log('');
// ###
var backorderCount = 0;
//console.log(data.items[0].product.inventories[0].availability);
for (var i = 0; i < itemsLength ; i++) {
var inventoriesLength = data.items[i].product.inventories.length;
for (var j = 0; j < inventoriesLength ; j++) {
if (data.items[i].product.inventories[j].availability === "backorder") {
backorderCount += 1;
console.log(data.items[i].product.googleId);
};
};
};
console.log('There are ' + backorderCount + ' items with an inventory availability of "backorder"');
console.log('');
var imageCount = 0;
for (var i = 0; i < itemsLength ; i++) {
if (data.items[i].product.images.length > 1) {
imageCount += 1;
console.log(data.items[i].product.googleId);
};
};
console.log('There are ' + imageCount + ' items with more than one image.');
console.log('');
// 4. Find all `canon` products in the items (careful with case sensitivity).
var canonCount = 0;
for (var i = 0; i < itemsLength ; i++) {
if (data.items[i].product.brand.toUpperCase() === "CANON") {
canonCount += 1;
console.log(data.items[i].product.googleId);
};
};
console.log('There are ' + canonCount + ' Canon-brand items.');
console.log('');
// 5. Find all `items` that have **product** **author** **name** of "eBay"
// and are brand "Canon".
var ebayCanonCount = 0;
for (var i = 0; i < itemsLength ; i++) {
if (data.items[i].product.brand.toUpperCase() === "CANON" &&
data.items[i].product.author.name.toUpperCase().indexOf('EBAY')) {
ebayCanonCount += 1;
console.log(data.items[i].product.googleId);
};
};
console.log('There are ' + ebayCanonCount + ' Canon-brand items from Ebay.');
console.log('');
// Print all the products with their **brand**, **price**, and an
// **image link**
console.log('-----------------------------------------------------');
console.log('ALL ITEMS IN DATA:');
console.log('-----------------------------------------------------');
for (var i = 0; i < itemsLength ; i++) {
console.log(data.items[i].product.googleId);
console.log(data.items[i].product.brand);
inventoriesLength = data.items[i].product.inventories.length;
for (var j = 0; j < inventoriesLength; j++) {
console.log('\tchannel: ' + data.items[i].product.inventories[j].channel);
console.log('\tprice: ' + data.items[i].product.inventories[j].price);
};
imagesLength = data.items[i].product.images.length;
for (var k = 0; k < imagesLength; k++) {
console.log('\timage: ' + data.items[i].product.images[k].link);
};
console.log('-----------------------------------------------------');
};