From 06baac250e610ef1b8a8d4f7220f6410639d0710 Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Tue, 13 Feb 2018 19:36:05 -0600 Subject: [PATCH 1/5] first function --- 04week/loops-practice.js | 58 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 04week/loops-practice.js diff --git a/04week/loops-practice.js b/04week/loops-practice.js new file mode 100644 index 000000000..6916b11e2 --- /dev/null +++ b/04week/loops-practice.js @@ -0,0 +1,58 @@ +'use strict' + +//The goal: +// Create a clean pull request with completed questions +// Commit at least 4 times/person +// answer questions below + +const latestExchangeRate = { + "base": "USD", + "date": "2018-02-13", + "rates": { + "AUD": 1.2742, + "BGN": 1.5858, + "BRL": 3.2954, + "CAD": 1.2604, + "CHF": 0.93424, + "CNY": 6.3443, + "CZK": 20.584, + "DKK": 6.0397, + "EUR": 0.81083, + "GBP": 0.72111, + "HKD": 7.8219, + "HRK": 6.0291, + "HUF": 253.11, + "IDR": 13640, + "ILS": 3.533, + "INR": 64.277, + "ISK": 101.68, + "JPY": 107.69, + "KRW": 1085.1, + "MXN": 18.631, + "MYR": 3.947, + "NOK": 7.899, + "NZD": 1.3736, + "PHP": 52.124, + "PLN": 3.3877, + "RON": 3.7773, + "RUB": 57.777, + "SEK": 8.0587, + "SGD": 1.3228, + "THB": 31.51, + "TRY": 3.8, + "ZAR": 11.982 + }, + multiplyByTen: (num) => num * 10 +} + +//create a function that returns the base and date for and object. Use latestExchangeRate as an example to test your function +const baseAndDate = () => { + return "base " + latestExchangeRate.base + " date " + latestExchangeRate.date +}; +baseAndDate(); + +//create a function that returns a list of availble currencies from a given object. Use latestExchangeRate as an example to test your function + +// create a function that console logs a string with the currency and the currency rate for each currency in a given object. For example, 'AUD is at a 1.2742 conversion rate'. Use latestExchangeRate as an example to test your function + +//create a function that takes in an object and console logs the result of the object's multiplyByTen method on each of the exchange rates. Use latestExchangeRate as an example to test your function From 2bc2ff879b56597d0b20920d3677a9446c78324a Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Tue, 13 Feb 2018 19:43:41 -0600 Subject: [PATCH 2/5] second function --- 04week/loops-practice.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/04week/loops-practice.js b/04week/loops-practice.js index 6916b11e2..269c71521 100644 --- a/04week/loops-practice.js +++ b/04week/loops-practice.js @@ -52,6 +52,10 @@ const baseAndDate = () => { baseAndDate(); //create a function that returns a list of availble currencies from a given object. Use latestExchangeRate as an example to test your function +const availableCurrencies = () => { + return Object.keys(latestExchangeRate.rates); +} +availableCurrencies() // create a function that console logs a string with the currency and the currency rate for each currency in a given object. For example, 'AUD is at a 1.2742 conversion rate'. Use latestExchangeRate as an example to test your function From 182c0f164baba1c076332d11935c1cf3be96baa3 Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Tue, 13 Feb 2018 20:12:48 -0600 Subject: [PATCH 3/5] third function --- 04week/loops-practice.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/04week/loops-practice.js b/04week/loops-practice.js index 269c71521..d828f78f7 100644 --- a/04week/loops-practice.js +++ b/04week/loops-practice.js @@ -57,6 +57,14 @@ const availableCurrencies = () => { } availableCurrencies() -// create a function that console logs a string with the currency and the currency rate for each currency in a given object. For example, 'AUD is at a 1.2742 conversion rate'. Use latestExchangeRate as an example to test your function +// create a function that console logs a string with the currency and the currency rate for each currency in a given object. For example, 'AUD is at a 1.2742 conversion rate'. Use latestExchangeRate as an example to test your function. +const stringAndCurrency = () => { + let rates = Object.keys(latestExchangeRate.rates); + let price = Object.values(latestExchangeRate.rates); + const rateLoop = rates.forEach((item, key) => { + console.log(rates[key] + " is at a " + price[key] + " conversion rate."); + }) +}; +stringAndCurrency(); //create a function that takes in an object and console logs the result of the object's multiplyByTen method on each of the exchange rates. Use latestExchangeRate as an example to test your function From b180c95ce3f03f3a1ea28e807b676d738829d2fd Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Tue, 13 Feb 2018 20:16:43 -0600 Subject: [PATCH 4/5] fourth function --- 04week/loops-practice.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/04week/loops-practice.js b/04week/loops-practice.js index d828f78f7..2a66de28c 100644 --- a/04week/loops-practice.js +++ b/04week/loops-practice.js @@ -68,3 +68,10 @@ const stringAndCurrency = () => { stringAndCurrency(); //create a function that takes in an object and console logs the result of the object's multiplyByTen method on each of the exchange rates. Use latestExchangeRate as an example to test your function +const rateMultiplied = () => { + let priceMultiplier = Object.values(latestExchangeRate.rates); + priceMultiplier.forEach((item, key) => { + console.log(priceMultiplier[key] * 10); + }) +} +rateMultiplied(); From 71108e02f179ac0b011b42eb381d9c424b10f25c Mon Sep 17 00:00:00 2001 From: Shay Hoffman Date: Tue, 13 Feb 2018 21:00:57 -0600 Subject: [PATCH 5/5] edits --- 04week/loops-practice.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/04week/loops-practice.js b/04week/loops-practice.js index 2a66de28c..62fbed177 100644 --- a/04week/loops-practice.js +++ b/04week/loops-practice.js @@ -46,14 +46,16 @@ const latestExchangeRate = { } //create a function that returns the base and date for and object. Use latestExchangeRate as an example to test your function -const baseAndDate = () => { +const baseAndDate = (obj) => { return "base " + latestExchangeRate.base + " date " + latestExchangeRate.date }; baseAndDate(); //create a function that returns a list of availble currencies from a given object. Use latestExchangeRate as an example to test your function -const availableCurrencies = () => { +//whenever you hear list, think array +const availableCurrencies = (obj) => { return Object.keys(latestExchangeRate.rates); + //object.keys creates a new array from the keys in the object } availableCurrencies()