Skip to content
Permalink
Browse files
minor fixes
  • Loading branch information
aa7401 committed Feb 20, 2019
1 parent 7549bd8 commit 139673141880ef5597e8e146fed4f2416a0aa694
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
@@ -99,10 +99,6 @@ const sqr = num => num * num
### 1.3 Callbacks
//TODO: need a replacemennt for the currency API (perhaps use screen scraping?) or books?
NOT an API at this stage but reading/writing files?
Since JavaScript supports _first class functions_, we can use a function in any place where we could use a literal, object or variable. Open the `currency.js` script and look at line 17. As you can see the `request` object has a key called `get` that stores a function (we have already covered this). This takes two parameters:
1. A string representing the url to be accessed.
@@ -142,15 +138,10 @@ Take a few moments to make sure you fully understand the syntax, you will be see

#### 1.3.2 Test Your Understanding

Lets improve the currency exchange tool. You will need to refer to the API [documentation](http://fixer.io) as you work through the tasks.
Lets apply our knowledge of callbacks to implement a simple quotes tool.

1. Replace the _function expression_ with an _anonymous function_.
2. Print the entire response body to the terminal window using [json.stringify()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).
3. The **base rate** defaults to the € (EUR) however the API allows you to set a different currency as the base rate:
1. Add a constant `base` to store your preferred currency.
2. Modify the URL using the API documentation to guide you.
4. Use the [Number.prototype.toFixed()](https://goo.gl/DU4hvd) to truncate the number to 2 decimal places.
5. Finally, modify your program so that it throws an error if it doesn't recognise either of the currency codes.
1. Create a json-formatted text file containing 10 quotes, you can find lots of these on websites such as [brainyquotes](https://www.brainyquote.com/topics/inspirational).
2. Create a callback function that

## 2 Objects

@@ -12,6 +12,6 @@ const printRates = (err, res, body) => {
console.log(`for each EUR you will get ${data.rates[symbol]} ${symbol} today`)
}

const url = `http://api.fixer.io/latest?symbols=${symbol}`
const url = 'currency.json'

request.get( url, printRates)

0 comments on commit 1396731

Please sign in to comment.