javascriptnumbered-list

Reorder JavaScript numbered list


Currently using this simple JS Code to create a numbered list:

<script type="text/javascript">
          
          let current_number = 10; 
          function insertNumber(){
            document.write(current_number)
            current_number--
          }
          
          
  </script>

Then using this code to display each number in order on my page:

<script type="text/javascript">insertNumber()</script>

My question is, how can I reorder this list? Right now, it begins from 10 and counts down to 1, but I'd like to start the list off with 1 and end with 10.

How can I do that? Thanks!


Solution

  • <script type="text/javascript">
              
      let current_number = 0; 
      function insertNumber(){
        if(current_number<=10)
        document.write(current_number)
        current_number++
      }   
              
    </script>