function showcurrency() {
var Currencybycountry = new Array();
Currencybycountry(US) = 100;
Currencybycountry(Europe) = 88.85;
Currencybycountry(GreatBritian) = 79.95;
Currencybycountry(India) = 6840;
Currencybycountry(Australia) = 143.61;
Currencybycountry(Canada) = 130.73;
for (var i = 0; i < Currencybycountry.length; i++) {
var thecurrency = Currencybycountry[i] ;
var id="Currency" + i;
var li = document.getElementbyld(id) ;
if (i == 0) {
li.innerHTML = "The Currency in the US was " + theCurrency;
} else {
li.innerHTML = "The Currency at " + i + " was " + theCurrency;
}
}
}
window.onload = showcurrency;
<h1>Currency</h1>
<li id="CurrencyUS"></li>
<li id="CurrencyEurope"></li>
<li id="CurrencyGreatBritian"></li>
<li id="CurrencyIndia"></li>
<li id="CurrencyAustralia"></li>
<li id="CurrencyCanada"></li>
Here is my problem, I am new to JavaScript and I need to create basically a bullet point list that uses the code to generate the currency. Meaning I need it to pop up with the title and then The currency in the US is 100. Currently all I can get it the title and bullet points to come up, it wont pull up the rest. Can someone please tell me what I am doing wrong?
Please format your JS code too using MarkDown syntax, like this:
```
function showcurrency() {
var Currencybycountry = new Array();
Currencybycountry(US) = 100;
Currencybycountry(Europe) = 88.85;
Currencybycountry(GreatBritian) = 79.95;
Currencybycountry(India) = 6840;
Currencybycountry(Australia) = 143.61;
Currencybycountry(Canada) = 130.73;
for (var i = 0; i < Currencybycountry.length; i++) {
var thecurrency = Currencybycountry[i] ;
var id = “Currency” + i;
var li = document.getElementbyld(id) ;
if (i == 0) {
li.innerHTML = "The Currency in the US was " + theCurrency;
} else {
li.innerHTML = "The Currency at " + i + " was " + theCurrency;
}
}
}
window.onload = showcurrency;
```
I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make easier to read.
See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>) will also add backticks around text.
Yeah you’re definitely not populating your array then, which is probably why nothing is returning. I would say try to refactor your code to match the example and/or the syntax from the page I linked. For instance, you need to denote an index for each country [0], [1], [2] and so on.