-
Notifications
You must be signed in to change notification settings - Fork 0
/
A3_part3.html
53 lines (46 loc) · 1.5 KB
/
A3_part3.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
52
53
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Part 2</title>
</head>
<body>
<style>
body{
background-color: aquamarine;
}
.evenNumbers{
margin-top: 15px;
margin-bottom: 15px;
}
</style>
<h1>Myat Thinzar Lynn - 12423051</h1>
<h2>Assignment 3 - Part 03</h2>
<h3>Sum of odd numbers between 0 to N</h3>
<div class="number-input">
<label input="quantity">Enter a number between 1 to 100</label>
<input type="number" id="input-number" name="quantity">
</div>
<div class="evenNumbers">
<button onclick="sumOfEvenNumbers()">Get the results</button>
</div>
<p id="final-result"></p>
<script>
function sumOfEvenNumbers(){
let sum = 0;
let userInput = parseFloat(document.getElementById('input-number').value);
if(userInput >= 1 & userInput <= 100){
for (var i = 0; i <= userInput; i++){
if (i % 2 != 0){
sum += i;
}
}
document.getElementById('final-result').innerHTML = "The sum of odd numbers between 0 and " + userInput + " is " + sum + "." ;
}else{
document.getElementById('final-result').innerHTML = "Please provide the number between 1 and 100!"
}
}
</script>
</body>
</html>