nebmucoy674
Coder
Hey all,
I'm beginning at JS and was going through some exercises online. I'm attempting to have (2) different arrays show when the appropriate button is clicked. However, the "cities" show for both, as opposed to the "countries" for the second. Any help is appreciated.
I'm beginning at JS and was going through some exercises online. I'm attempting to have (2) different arrays show when the appropriate button is clicked. However, the "cities" show for both, as opposed to the "countries" for the second. Any help is appreciated.
JavaScript:
<body>
<! attempting button>
<button onclick="document.getElementById('places').innerHTML = text">Click me for cities!</button>
<p id="places"></p>
<script>
const cities = ["Albany", "Denton", "Asheville", "Charlotte", "Dallas", "Houston"];
let i = 0;
let text = "";
while (cities[i]) {
text += cities[i] + "<br>";
i++;
}
</script>
<br>
<button onclick="document.getElementById('countries').innerHTML = text">Click me for countries!</button>
<p id = "countries"></p>
<script>
const countries = ["USA", "Bangladesh", "Sweden", "UAE", "Italy", "India", "Belgium", "Denmark", "Netherlands", "Nepal"];
let text = '';
for (let i = 0; i < countries.length; x++) {
text += countries[i] + "<br>";
}
</script>
</body>