https://github.com/kodervine/pryto-js
Update cryptocurrency price
https://github.com/kodervine/pryto-js
Last synced: 3 months ago
JSON representation
Update cryptocurrency price
- Host: GitHub
- URL: https://github.com/kodervine/pryto-js
- Owner: kodervine
- Created: 2022-08-28T06:40:57.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2022-09-13T08:06:57.000Z (over 2 years ago)
- Last Synced: 2025-01-20T07:46:04.440Z (4 months ago)
- Language: JavaScript
- Size: 240 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Pryto
Update cryptocurrency price
# Selecting the input value
So I selected the select element from the html file
Then, I added a 'change" "event listener. So whenever the options selects someone else, I can update the selected value
To access the innerText, I used the index of the options element with the logic [dropDown.selectedIndex] property as the index of the drop-down menu and set it to coinNameSo this innerText will be used to compare with the crypto currency symbol of the fetch api
# Looping over the API data
I used the for...in loop on the JSON file
Then for each iteration in the loop, I used the selected **_coinName_** to compare the data (object keyName) from the fetchedData.rates
Then, I saved this to a new variable for future mathematical purposes - const **_coinValue_**;So I created a new variable = **_newUSDValue, newNairaValue_** so that when I get the value of each coin, it will be used to be divided by the dollar amount and naira amount and displayed on the screen
In this case, I needed to have 2 logic in place for the "getValueOfNumber". This is the amount of the units a person wants to know the crypto current rates
1. To use parseInt when the amount from the input doesn't have decimal point
2. To use parseFloat when the amount contains any decimal pointSo, i used the new ES6 logic (Number.isInterger) to make the logic work
Then I set a new variable for the mathematics
For the USD, I created a conditional to confirm if the coinValue is less than 1, it will round it off to 2 decimals. Else, it rounds it off to the nearest whole number
For the naira, I didn't bother. Just set it to be rounded off immediately
# Get input value from the dom
I selected the input number value from the DOM. This will be used to multiply whatever current value being inputed by the client on the screen
Used some validation to convert to number primitive type, then multiplied the value, with the new naira value
Finally appended the result to the screen provided in the HTML file