@tech4teachers/

Factorial HTML-i-fied "app"

HTML, CSS, JS

No description

fork
loading
Files
  • index.html
  • script.js
  • style.css
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>Factorial html app from Udacity JS 4.14 (quiz 4-7)
    </title>
    <link href="style.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <script type="text/javascript"></script>  
    <script src="script.js"></script>
    <script type="text/javascript"> 
        function calculate(){
        var outputText=document.getElementById("Answer");
        var numGiven=parseInt(document.getElementById("integer").value); 

        var solution=1;
        if(isNaN(numGiven) || numGiven < 1 || numGiven > 12){
            outputText.innerHTML ="Invalid Entry";
        } 
        else{for (numLeast =1; numLeast<= numGiven; numLeast++)
        {
        solution *= numLeast;
        }
        outputText.innerHTML=" The factorial of "+numGiven+" is; "+solution;
        }
    }


     </script>
    <div>
        <form>
            What Number would you like to find the factorial of?
            <input type="number" id="integer" name="integer" min-"1" max="12"/><br/>
            <input type="button" value="compute" onclick="calculate();"/>
            
        </form>
    </div>

    <p></p>
    <div>
        <p id="Answer"></p>
    </div>

  </body>
</html>
result
console