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

Conditionals and Loops - Wei Jun #112

Open
wants to merge 3 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
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>Google Shopping - Conditionals and Loops</title>
</head>
<body>
<h1>Google Shopping - Conditionals and Loops</h1>
<script src="products.js"></script>
<script src="script.js"></script>
</body>
</html>
3 changes: 3 additions & 0 deletions products.js
Original file line number Diff line number Diff line change
Expand Up @@ -1137,3 +1137,6 @@ var products = {
}
]
}


console.log(products);
167 changes: 167 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
//1. products.items[0].product.brand = " nikon" if i want to find brand
//2. print kind of shopping#product


//setting variables to use
console.log(products.items.length);

var prodItem = products.items;
/****************************/

//1. - Go through the `items` and find all results that have `kind` of `shopping#product`. Print the count of these results. Where else is this count information stored in the search results?

var counter = 1;
/*
for (var i = 0; i < prodItem.length; i++) {
if(prodItem[i].kind === "shopping#product") {
// counter =+
console.log(counter++);

}
}
*/

/****************************/

//2.Print the `title` of all items with a `backorder` availability in `inventories`.
// check is availability equals to "inStock"
// products.items[1].product.inventories[0].availability
//print products.items[1].product.title
/*
for (var i = 0; i < prodItem.length; i++) {
if(prodItem[i].product.inventories[0].availability == "inStock") {
// console.log(counter++)
console.log(counter++ + "." + " "+ "In stock: " + prodItem[i].product.title)
}
}
*/

/****************************/
/*
//3. Print the `title` of all items with more than one image link.
//find object directory to image key.
//image is in array. find length
// if length more than 1
//products.items[0].product.images.length

for (var i = 0; i < prodItem.length; i++) {
if(prodItem[i].product.images.length > 1 ) {
counter++;
console.log(prodItem[i].product.images);
// console.log(counter++ + "." + " "+ "In stock: " + prodItem[i].product.title)
}
}
console.log(counter);

*/
/****************************/
/*
//4. Print all "Canon" products in the items (careful with case sensitivity)
//prodItem[1].product.brand
for (var i = 0; i < prodItem.length; i++) {
if(prodItem[i].product.brand == "Canon" ) {
// console.log(counter++)
console.log(counter++ + "." + " "+ "Brand: " + prodItem[i].product.brand + ", " + products.items[i].product.title )
}
}&& prodItem[i].product.brand
*/

/****************************/
//x = asdf Big
// var y = x.search("Big");
// console.log(y);
//5. Print all `items` that have an author name of "eBay" and are brand "Canon".
/*
for (var i = 0; i < prodItem.length; i++) {
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");
// console.log(hasName)

if(brand == "Canon" && hasName >= 0) {
// console.log(counter++)
console.log(i+ ". " + " "+ "Brand: " + brand + ", " + title + ", " + author);
}
}
*/

/****************************/
// 6. Print all the products with their **brand**, **price**, and an **image link**
/*
for (var i = 0; i < prodItem.length; i++) {
var brand = prodItem[i].product.brand;
var title = products.items[i].product.title;
var author = prodItem[i].product.author.name;
var price = prodItem[i].product.inventories[0].price;
var imgLink = prodItem[i].product.images[0].link;
// var hasName = author.search("eBay");
// console.log(hasName)
// console.log(counter++)
console.log(i+ ". " + " "+ "Brand: " + brand + ", " + "Price: " + "$" + price + ", " + "Image Link: " + imgLink);

}
*/
/****************************/
//7. Prompt the user for the product brand and print only those products.
// Prompt the user if they want to see only new or used items.
/*
var userInputun = prompt("Search for brands (Sony, Canon, Nikon)").toLowerCase();
var userInput = userInputun.charAt(0).toUpperCase() + userInputun.slice(1, userInputun.length);
// console.log(userInput);
var newOrOld = prompt("Would you want to view a new or old item?").toLowerCase();

function searchBrand(thingBrand, thingNeworOld) {
for (var i = 0; i < prodItem.length; i++) {
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;
// console.log(hasName)

if(brand == thingBrand && condition == thingNeworOld) {
// console.log(counter++)
console.log(i+ ". " + " "+ "Title: " + title + ", " + imgLink);
}
}
}

searchBrand(userInput,newOrOld);
*/
/***************************/
// 8.Prompt the user what kind of search they want to do- search by brand or search by condition.
// Then prompt the user to put in ther actual search value- (new/used for condition *or* brand name for brand)
var i = 0;
var userinputOne = prompt("Search our list by brand? Or by condition?").toLowerCase();

if (userinputOne === "brand") {
alert("Type in a brand! (Sony, Nikon, Canon....)")
i++
} else if (userinputOne === "condition") {
alert("New or refurbished?")
i++
} else {
prompt("Please reenter brand or condition.")
}
/*
function searchBrandorCondition(thingBrand, thingCondition) {
for (var i = 0; i < prodItem.length; i++) {
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;
// console.log(hasName)

if(brand == thingBrand && condition == thingNeworOld) {
// console.log(counter++)
console.log(i+ ". " + " "+ "Title: " + title + ", " + imgLink);
}
}
}
searchBrandorCondition(userInput,)
*/