Please help. I'm just new at this. I've been trying to output 2 set of arrays with a loop and I couldn't seem to figure out.
Here's my code:
<script>
cars=["BMW","Volvo","Saab","Ford"];
type=["Sports","Luxury","Premium","Economy"];
var i=0;
var a=0;
while (cars[i])
{
document.write(cars[i] + " - " + type[a]"<br/>");
i++;
}
</script>
What I want to be the result is:
BMW - Sports
Volvo - Luxury
Saab - Premium
Ford - Economy
Thank you in advance!
document.writein a real application in a script block unless you're putting it inside a document ready handler like (using jQuery)$(function() { ... }). Writing from inside a script block directly will have performance penalties for most browsers as they have to stop rendering and recalculate all the html on the page.forloop makes far more sense than awhile loop