-
Notifications
You must be signed in to change notification settings - Fork 0
/
A3_part1.html
51 lines (46 loc) · 1.61 KB
/
A3_part1.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
48
49
50
51
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Part 1</title>
</head>
<body>
<style>
body{
background-color: rgb(167, 221, 87);
}
.factorial{
margin-top: 15px;
margin-bottom: 15px;
}
</style>
<h1>Myat Thinzar Lynn - 12423051</h1>
<h2>Assignment 3 - Part 01</h2>
<h3>Finding the factorial of N</h3>
<div class="number-input">
<label for="quantity">Enter the number between 1 and 20</label>
<input type="number" id="input-number" name="quality">
</div>
<div class="factorial">
<button onclick="findFactorial()">Find the factorial</button>
</div>
<p id="final-numbers"></p>
<script>
function findFactorial(){
let inputNumber = parseFloat(document.getElementById('input-number').value);
if (inputNumber === 0 || inputNumber === 1){
document.getElementById('final-numbers').innerHTML = "The Factorial value of "+ inputNumber + " is 1.";
}else if(inputNumber >= 2 && inputNumber <= 20){
for (var i = inputNumber - 1; i >= 1; i--){
inputNumber *= i;
}
document.getElementById('final-numbers').innerHTML = "The Factorial value of the input number is " + inputNumber + ".";
}
else{
document.getElementById('final-numbers').innerHTML = "Error, " + inputNumber + " is out of range."
}
}
</script>
</body>
</html>