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

Neel #111

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open

Neel #111

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
10 changes: 10 additions & 0 deletions googleShopping.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script src="products.js"></script>
<script src="googleShopping.js"></script>
</body>
</html>
135 changes: 135 additions & 0 deletions googleShopping.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
console.log("hello");

console.log(products);

// //Question 1
console.log("Question 1");
var count = 0

for (var i = 0; i < products["items"].length; i++) {
var product = products["items"][i];
if (product["kind"] === "shopping#product"){
count++;
}
}
console.log("Count base on loop: " + count);
console.log("Count retrived from search result: " + products["currentItemCount"]);

// //Question 2
console.log("Question 2");

for (var i = 0; i < products["items"].length; i++) {
var item = products["items"][i];
var inventory = item.product;
if (inventory.inventories[0].availability === "backorder") {
console.log(inventory.title);
}
}

// //Question 3
console.log("Question 3");

for (var i = 0; i < products["items"].length; i++) {
var item = products["items"][i];
var imgs = item.product["images"];
if (imgs.length>0) {
console.log(item.product.title);
}
}

//Question 4
console.log("Question 4");

for (var i = 0; i < products["items"].length; i++) {
var item = products["items"][i];
var make = item.product.brand;
if (make === ("Canon" || "canon")) {
console.log(item.product.title);
}
}

//Question 5
console.log("Question 5");

for (var i = 0; i < products["items"].length; i++) {
var item = products["items"][i];
var make = item.product.brand;
var auth = item.product.author.name;
if ((make === ("Canon" || "canon")) && (auth.includes("eBay"))) {
console.log(item.product.title);
}
}

//Question 6
console.log("Question 6");

for (var i = 0; i < products["items"].length; i++) {
var item = products["items"][i];
var make = item.product.brand;
var prc = item.product.inventories[0].price;
var img = item.product["images"][0];
console.log("Item: " + item.product.title + " , " + " Brand: " + make + " , " + "Price: $" + prc + " , " + "Image: " + img.link );
}

//Question 7
console.log("Question 7");

var userInput = prompt("What brand are you searching for?");
console.log(userInput);

for (var i = 0; i < products["items"].length; i++) {
var item = products["items"][i];
var make = item.product.brand;
var prc = item.product.inventories[0].price;
var img = item.product["images"][0];
if(userInput.toLowerCase() == make.toLowerCase()) {
console.log("Item: " + item.product.title + " , " + " Brand: " + make + " , " + "Price: $" + prc + " , " + "Image: " + img.link );
}
}

//Question 8
console.log("Question 8");

var userInput = prompt("Would you prefer a New or Old item?");
console.log("List of all " + userInput.toUpperCase() + " items available: ");

for (var i = 0; i < products["items"].length; i++) {
var item = products["items"][i];
var cond = item.product.condition;
var make = item.product.brand;
var prc = item.product.inventories[0].price;
var img = item.product["images"][0];

if(userInput.toLowerCase() == cond.toLowerCase()) {
console.log("Item: " + item.product.title + " , " + " Brand: " + make + " , " + "Price: $" + prc + " , " + "Image: " + img.link );
}
}

//Question 9
console.log("Question 9");

var userInput = prompt("Search by 'Brand' or by 'Condition'?");
var userInput = userInput.toLowerCase();

if (userInput === "brand") {
var userInput1 = prompt("What brand are you searching for?");
} else if (userInput = "condition") {
var userInput1 = prompt("Would you prefer a New or Old item?");
}

console.log("List of all items available based on search criteria :" + userInput1.toUpperCase());

for (var i = 0; i < products["items"].length; i++) {
var item = products["items"][i];
var cond = item.product.condition;
var make = item.product.brand;
var prc = item.product.inventories[0].price;
var img = item.product["images"][0];

if(userInput1.toLowerCase() == make.toLowerCase()) {
console.log("Item: " + item.product.title + " , " + " Brand: " + make + " , " + "Price: $" + prc + " , " + "Image: " + img.link );
} else if (userInput1.toLowerCase() == cond.toLowerCase()) {
console.log("Item: " + item.product.title + " , " + " Brand: " + make + " , " + "Price: $" + prc + " , " + "Image: " + img.link );
}
}