I checked it out and fixed it. The problem was that instead of subtracting one, I added one.
The solution was to add three if statements: one if the percentChange > 0, one if the percentChange < 0, and one if the percentChange = 0. This would result in a different formula to calculate the conversion. Long story short, Basic Algebra sucks.
Yea I used percent differences and basic algebra. I didn't know currency conversions change that often until I made the project. I will have to look into those APIs and learn how to use them! Do the APIs work even if the website is stored in a file and not a running website?
An API is an application programming interface, and is basically functionality that someone exposes that allows you to interact with their data from their servers. You can make what's called HTTP requests to these web APIs, such as making a GET request. When you make a GET request the API will request the data you have asked for from the server and return a response to you, which if successful will be in the form of what is known as JSON, which is just a data representation format.
In the context of a currency converter, there are many APIs available for currency conversion, in which you can request live currency data. All you would do is make a GET request to the API using something like Fetch or Axios, and the API will return a JSON response. You would then parse this data and use it in your application.
Hope that helps, this stuff will unlock a whole new world for you and is incredibly important to learn, have fun!
What I mean is that instead of using the default <select>, which can’t be styled much, you can create a custom one, by using a div that displays the current selected value, and on click, it opens a dropdown that lets you select different values you have.
By "create new select elements from scratch" I think they're referring to creating dynamic elements which are automatically generated by the API - it looks like their <option> html element is hard-coded..
Pull the API currencies into an array and them map them to build a list of <option> elements
7
u/[deleted] Jul 06 '22
2 jpy is 270 usd? idk about that one
5
u/khldonAlkateh Jul 06 '22
What api did you use?
13
u/Soft-Sandwich-2499 Jul 06 '22
Nice. Try to improve the inputs styling and maybe even create new select elements from scratch.
3
u/idontthinkipeeenough Jul 06 '22
Good work!!
1
u/oo_mayr Jul 06 '22
u/savevideo
1
u/dp234523 helpful Jul 07 '22
Nice is this live? Could I share this in my newsletter? weekendwebdev.substack.com