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

Adam Budik's Homework for 07/08/14 #3

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
10 changes: 4 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#JS Control Lab
#JS Control Lab - Adamgit st

##Part 1 - Looping Exercises
Complete the following set of problems in lab.md by making new files.

Use `node` to run and check your ouput

##Part 2 - Google Products JSON
Answering the following questions on `google_shopping.md`. Use the file `google_shopping.js` to check your output.
Answering the following questions on `google_shopping.md`. Use the file `google_shopping.js` to check your output.

Change that is visible!
13 changes: 13 additions & 0 deletions filterLongWords.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// ##filterLongWords.js
// Hardcode an array of words. Have a variable maxLength,
// and push those words to only to an array filter long words.
// Return words less than maxLength.
array = ["puppy", "a", "it", "kitten",
"animals", "frog", "imp", "creature"];

for (var i = 0, maxLength = 6; i < array.length; i++) {
if (array[i].length < maxLength) {
console.log(array[i]);

}
}
99 changes: 97 additions & 2 deletions google_shopping.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,100 @@
var data = require("./products.json")

// Write your solutions below
// The `kind` of results you're are dealing are
// `shopping#products`. Go through the `items` and find all
// results that have `kind` of `shopping#product`. How many
// are there? Where else is this count information stored
// in the search results?

var countProduct = 0;
var allItems = data["items"];


for (var i = 0; i < allItems.length; i++) {
var currentItem = allItems[i];
if (currentItem["kind"] === "shopping#product") {
countProduct += 1;
}
}
console.log(countProduct);

// ANSWER:
// I ran my code to receive 25 instances of 'shopping#product'
// with the 'kind' in 'items.' This information is also available
// in 'itemsPerPage' and 'currentItemCount,' as there are only
// 25 products shown per page.'




// Find all items with a `backorder` availability
// in `inventories`.

var allItems = data["items"];

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





// Find all items with more than one image link.

var allItems = data["items"]

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





// Find all `canon` products in the items (careful
// with case sensitivity).

var allItems = data["items"];

for (var i = 0; i < allItems.length; i++) {
if (allItems[i]["product"]["brand"] === "Canon")
console.log(allItems[i]["product"]["title"]);
}
}





// Find all `items` that have **product** **author**
// **name** of "eBay" and are brand "Canon".

var allItems = data["items"];

for (var i = 0; i < allItems.length; i++) {
if ((allItems[i]["product"]["brand"] === "Canon") &&
(allItems[i]["product"]["author"]["name"].indexOf("eBay") !== -1)) {
console.log(allItems[i]["product"]["title"]);
}
}



// Print all the products with their **brand**,
// **price**, and a **image link**

var allItems = data["items"];

for (var i = 0; i < allItems.length; i++) {
brand = allItems[i]["product"]["brand"];
price = allItems[i]["product"]["inventories"][0]["price"];
imageLink = allItems[i]["product"]["images"][0]["link"];
console.log("Brand: " + brand + " Price: $" + price + " Image Link: " + imageLink);
}

console.log(data["items"]);
43 changes: 43 additions & 0 deletions grade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// ##grade.js
// Output the following code from a variable with with a code
// returns grade for the score, either "A", "B", "C", "D", or "F".

function gradeToNum(num) {
var gradeLetter = ""
;

switch(true)
{
case (num <= 0):
gradeLetter = "What are you trying here?";
break;

case ((num >= 1) && (num <= 59)):
gradeLetter = "A big fat F";
break;

case ((num >= 60) && (num <= 69)):
gradeLetter = "Uhh..no way, dude..D?";
break;

case ((num >= 70) && (num <= 79)):
gradeLetter = "You're doing okay, cool C";
break;

case ((num >= 80) && (num <= 89)):
gradeLetter = "Not bad! Beautiful B";
break;

case ((num >= 90) && (num <= 100)):
gradeLetter = "wow! Awesome A!";
break;

default:
gradeLetter = "Umm..1-100 okay?"
break;
}

return gradeLetter;
}

console.log(gradeToNum(90))
3 changes: 0 additions & 3 deletions lab.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ After that work on the questions on google_shopping.js
##reverse.js
Write a program that will take a hardcoded string, and console log the reversed version of it. Use a `for` loop

`var inputString = "building"`

##filterLongWords.js
Hardcode an array of words. Have a variable maxLength, push words that are less than the maxLength into a new array, and console.log that.


##grade.js
Output the following letter grade from a variable with with a test score. Display either "A", "B", "C", "D", or "F", for an score that is an integer between 0 and 100. Try and use a `switch` statement.

Expand Down
19 changes: 19 additions & 0 deletions pluralizer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Take an input like:
// thing = "cat"
// count = "5"
// ```
// and output the pluralized form
// of the word like "5 cats" or "1 dog"..

function isPlural(thing, count) {
//singular if less than one
if (count < 2) {
console.log("There is " + count + " " + thing + ".");
}
//plural else
else {
console.log("There are " + count + " " + thing + "s.");
}
}
isPlural("cat", 5)
isPlural("dog", 1)
21 changes: 21 additions & 0 deletions reverse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// ##reverse.js
// Write a program that will take a hardcoded string,
// and console log the reverse it. Use a for loop


function reverse(inputString) {
//jump back to front throughout inputString, while working
//through loop.
for (var array = [], i = 1; i <= inputString.length; i++) {
//store letters into array
array.push(inputString.charAt(inputString.length - i));

}
//join array into a new reversed string
var newString = array.join('');
console.log("The reverse of " + "\'" + inputString + "\'" +
" is " + "\'" +newString + ".\'");

}

reverse("building")
16 changes: 16 additions & 0 deletions tempConvert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// ##tempConvert.js
// Convert a temperature from F to C.
// Convert it to fahrenheit and output "NN°C is NN°F".

function isTemperature(fahrenheit){
//Convert a temperature
//Deduct 32, then multiply by 5, then divide by 9
var minusF = fahrenheit - 32;
var multiplyF = minusF * 5;
var divideF = multiplyF/9;
var celsius = Math.floor(divideF);
//console.log "*C is *F"
console.log(celsius + "C is " + fahrenheit + "F.");
}

isTemperature(212)