-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fallback mechanism #90
Comments
Whats the difference between |
|
brother please help.. i am new to programing. just making currency converter. |
@gaganpreetsharma000, have you seen the migration instruction? It's pretty clear. By the url, https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/inr.json you are fetching data in the rate INR/XXX, where XXX is another currecy from the got JSON, e.g. USD. In that case, one INR costs 0.012070684 USD. As you need usd/inr, you have to fetch data USD/XXX: https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.json, where you'll get a cost of one USD in different currencies, and select the needed one from the received JSON, in your case INR. Try async function getUsdInrRate() {
// This url will give you currencies UDS/XXX
const url = 'https://cdn.jsdelivr.net/npm/@fawazahmed0/currency-api@latest/v1/currencies/usd.min.json'
// Fetch data and get INR rate
const inr = await fetch(url)
.then(response => response.json())
.then(data => data['usd'].inr)
console.log(inr)
}
getUsdInrRate() You'll get current rate Tip Use min versions of the files to get reduced files (whitespaces deleted), and faster responses, I assume. |
i face the same issue do you have its solution ??? |
check out my github page https://gowthamssr.github.io/currency_converter/ are u looking for this functionality @KerasirovED helped me ................................................................................................................................................................................................................................ const dropdowns = document.querySelectorAll(".dropdown select"); for (let select of dropdowns) { select.addEventListener("change", (evt) => { const updateExchangeRate = async () => { let rate = data[from][to]; let finalAmount = amtVal * rate; const updateFlag = (element) => { btn.addEventListener("click",(evt) => { // const URL = updateExchangeRate(); window.addEventListener("load",() => { follow me on https://www.linkedin.com/in/gowtham-ssr-1a5858280/ |
const Base_Url= "https://api.exchangeratesapi.io/v1/latest? access_key = API_KEY"; const dropdown=document.querySelectorAll(".drop_down select"); for(let select of dropdown){ select.addEventListener("change",(evt)=>{ const updateExchangeRate=async()=>{
const updateflag=(element)=>{ document.addEventListener("load",()=>{ this is my JS code i have tried different apis but it does not run, i am getting this error=> |
@Aishaarain const dropdown = document.querySelectorAll(".drop_down select"); for (let select of dropdown) {
} const updateExchangeRate = async () => {
}; const updateFlag = (element) => { btn.addEventListener("click", async (evt) => { document.addEventListener("DOMContentLoaded", () => { |
<!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:11.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
code
{mso-style-priority:99;
font-family:"Courier New";}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
font-size:10.0pt;
font-family:"Courier New";}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:"Courier New";}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--> Sent from Mail for Windows From: GowthamSent: Monday, July 1, 2024 6:25 PMTo: fawazahmed0/exchange-apiCc: Aishaarain; MentionSubject: Re: [fawazahmed0/exchange-api] Fallback mechanism (Issue ***@***.*** API_KEY = 'your_api_key_here'; // Replace with your actual API keyconst Base_Url = https://api.exchangeratesapi.io/v1/latest?access_key=${API_KEY};const dropdown = document.querySelectorAll(".drop_down select");const btn = document.querySelector("form button");const fromCurr = document.querySelector(".from select");const toCurr = document.querySelector(".to select");const msg = document.querySelector(".msg");for (let select of dropdown) {for (let currcode in countryList) {let newOption = document.createElement("option");newOption.innerText = currcode;newOption.value = currcode;select.append(newOption);if (select.name === "from" && currcode === "USD") {newOption.selected = "selected";} else if (select.name === "to" && currcode === "PKR") {newOption.selected = "selected";}}select.addEventListener("change", (evt) => { updateFlag(evt.target);});}const updateExchangeRate = async () => {let amount = document.querySelector(".amount input");let amtValue = amount.value;if (amtValue === "" || amtValue < 1) {amtValue = 1;amount.value = "1";}const URL = `${Base_Url}&base=${fromCurr.value}&symbols=${toCurr.value}`;let response = await fetch(URL);if (!response.ok) { msg.innerText = "Error fetching exchange rate."; return;}let data = await response.json();let rate = data.rates[toCurr.value]; let finalAmount = amtValue * rate;msg.innerText = `${amtValue} ${fromCurr.value} = ${finalAmount} ${toCurr.value}`;console.log(rate);console.log(data);console.log(finalAmount);};const updateFlag = (element) => {let currcode = element.value;let countrycode = countryList[currcode];let newsrc = https://flagsapi.com/${countrycode}/flat/64.png;let image = element.parentElement.querySelector("img");image.src = newsrc;};btn.addEventListener("click", async (evt) => {evt.preventDefault();updateExchangeRate();});document.addEventListener("DOMContentLoaded", () => {updateExchangeRate();});—Reply to this email directly, view it on GitHub, or unsubscribe.You are receiving this because you were mentioned.Message ID: ***@***.***>
|
@Gowthamssr , i think there is another issue in my code , i have tried alot APIS but none is working, do you know why it is happened. this error is displayed=> this is my code=> const dropdown=document.querySelectorAll(".drop_down select"); for(let select of dropdown){ select.addEventListener("change",(evt)=>{ const updateExchangeRate=async()=>{
let response = await fetch(URL); let finalAmount = amtValue * rate; const updateflag=(element)=>{ document.addEventListener("load",()=>{ |
Hello, This link is not working Could you please help me to get a working URL? |
Fallback URL:
Pseudo code:
For example, if you want to fetch
eur
:The text was updated successfully, but these errors were encountered: