Reputation: 1
I am trying to populate a dropdown box but I keep getting an undefined
error for all currencies when i reference them.
This code is given to me from a third party to accomplish the simple goal of populating a dropbox and editing a little text and i have no idea why the variable I need from the referenced js
file is coming up undefiened
var allCurrencies = {
"AED": "United Arab Emirates Dirham",
"BTC": "Bitcoin",
"CAD": "Canadian Dollar",
"EUR": "Euro",
"JPY": "Japanese Yen",
"RUB": "Russian Ruble",
"USD": "United States Dollar"
};
// Initial data for exchange rates
var exchangeRates = {
"disclaimer": "Usage subject to terms: https://openexchangerates.org/terms",
"license": "https://openexchangerates.org/license",
"timestamp": 1534107604,
"base": "USD",
"rates": {
"BTC": 0.000157753542,
"CAD": 1.316853,
"EUR": 0.879353,
"JPY": 110.46550427,
"USD": 1,
}
};
/* Your solution goes here */
<head>
<meta charset="UTF-8">
<title>Currency Exchange</title>
<script src="jquery-3.2.1.min.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<link href="style.css" rel="stylesheet">
<script src="currex.js" defer></script>
<script>
</script>
</head>
I am just looking for any starting point to help with this
Upvotes: 0
Views: 66
Reputation: 943142
<script src="currex.js" defer></script>
You deferred the loading of the script, so it won't have run before the script element that immediately follows it.
Since it hasn't run yet, the variable isn't defined.
Remove the defer
attribute.
Upvotes: 3