'Create multiplication table with minimum and maximum inputs [duplicate]

I have a program that creates a multiplication table using loops. The code has 2 input part: number(multiplicand) & multiplier. The user input requires 2 numbers to define the parameter but each input must be between 2 - 10, otherwise an alert box appears saying that the inputs are larger than 2 - 10. However, there are still no outputs.

Is there a mistype in the code? Thanks.

Code:

<!DOCTYPE html>
<html lang="en">
  <head>
    <style>
     
    </style>
    <script>
      function addNumbers() {
    
    var multiplier;
        if (multiplier > 10 && multiplier < 2)
        {
            alert("Multiplier above maximum of 10");
            return;
    }
    
    var number;
        if (number < 2 && multiplier < 2)
        {
            alert("Number below minimum of 2");
            return;
    }
    
        var result = "";

    number = Number(document.getElementById("number").value);
    multiplier = Number(document.getElementById("multiplier").value);        
        
        
        for(var i = number; i <= multiplier; i++){
          result = result + "<p>"+ number + "*" + i + "=" + number * i+"</p>";
        }

        document.getElementById("result").innerHTML = result;
      }
    </script>
  </head>
  <body>
    </br>
    Enter the number : <input id="number" />
    Enter the multiplier : <input id="multiplier" />
    <br>    
    </br>
    <button onclick="addNumbers()">Print Multiplication table</button> 
    <div id="result">

  </body>
</html>


Solution 1:[1]

just assign variable before condition.

var number = Number(document.getElementById("number").value);

var multiplier = Number(document.getElementById("multiplier").value);

Solution 2:[2]

I think DOM NodeLists are "live" collections in normal DOM use ("live" I think was the spec term in the W3C spec, the Microsoft docs calls them dynamic: https://docs.microsoft.com/en-us/dotnet/standard/data/xml/dynamic-updates-to-nodelists-and-namednodemaps) so your attempt $childNodes = $sequence.ChildNodes stores that live NodeList in a variable and as such a collection it reflects any change to the DOM tree. The Powershell use of piping that collection to Sort-Object with $sequence.ChildNodes | Sort-Object -Property "Name" does not return an XmlNodeList or other live/dynamic collection, rather it returns an array of objects, e.g. XmlNode[] or object[], so that way your code works as you want it to work as you later process that array and not the XmlNodeList that tracked the changes to the DOM tree.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mihir
Solution 2