-4
<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?

1 Answers1

1

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"?

Community
  • 1
  • 1
user2267175
  • 595
  • 5
  • 14