diff --git a/README.md b/README.md index 4c75b62..691d878 100644 --- a/README.md +++ b/README.md @@ -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. \ No newline at end of file +Answering the following questions on `google_shopping.md`. Use the file `google_shopping.js` to check your output. + +Change that is visible! \ No newline at end of file diff --git a/filterLongWords.js b/filterLongWords.js new file mode 100644 index 0000000..290e5b9 --- /dev/null +++ b/filterLongWords.js @@ -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]); + + } +} \ No newline at end of file diff --git a/google_shopping.js b/google_shopping.js index 71f88ba..bc26878 100644 --- a/google_shopping.js +++ b/google_shopping.js @@ -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"]); \ No newline at end of file diff --git a/grade.js b/grade.js new file mode 100644 index 0000000..9057aa2 --- /dev/null +++ b/grade.js @@ -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)) \ No newline at end of file diff --git a/lab.md b/lab.md index 1e3dcd6..62c0fab 100644 --- a/lab.md +++ b/lab.md @@ -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. diff --git a/pluralizer.js b/pluralizer.js new file mode 100644 index 0000000..3788623 --- /dev/null +++ b/pluralizer.js @@ -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) \ No newline at end of file diff --git a/reverse.js b/reverse.js new file mode 100644 index 0000000..241090c --- /dev/null +++ b/reverse.js @@ -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") \ No newline at end of file diff --git a/tempConvert.js b/tempConvert.js new file mode 100644 index 0000000..199b9ea --- /dev/null +++ b/tempConvert.js @@ -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) \ No newline at end of file