<script language=javascript type="text/javascript">
for (i=0;i < 10; i++) {
document.write(i);
}
</script>
How can I print the output of this code which is 0123456789 backwards?
<script language=javascript type="text/javascript">
for (i=0;i < 10; i++) {
document.write(i);
}
</script>
How can I print the output of this code which is 0123456789 backwards?
just set index as highest value, then run it to -1, javascript will automaticly break it at 0.
for (var i=9; i > -1; i-=1) {
box.innerHTML += i+" <br/>";
}
<div id="box"></div>
Edit: Reasons to use a html element and write to that instead of using document.write can be found here: Why is document.write considered a "bad practice"?