File tree Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Expand file tree Collapse file tree 1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+ < head >
4
+ < meta charset ="UTF-8 ">
5
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6
+ < title > Part 2</ title >
7
+ </ head >
8
+ < body >
9
+ < style >
10
+ body {
11
+ background-color : aquamarine;
12
+ }
13
+ .evenNumbers {
14
+ margin-top : 15px ;
15
+ margin-bottom : 15px ;
16
+ }
17
+ </ style >
18
+
19
+ < h1 > Myat Thinzar Lynn - 12423051</ h1 >
20
+ < h2 > Assignment 3 - Part 02</ h2 >
21
+ < h3 > Sum of even numbers between 0 to N</ h3 >
22
+
23
+ < div class ="number-input ">
24
+ < label input ="quantity "> Enter a number between 1 to 100</ label >
25
+ < input type ="number " id ="input-number " name ="quantity ">
26
+ </ div >
27
+
28
+ < div class ="evenNumbers ">
29
+ < button onclick ="sumOfEvenNumbers() "> Get the results</ button >
30
+ </ div >
31
+
32
+ < p id ="final-result "> </ p >
33
+
34
+ < script >
35
+ function sumOfEvenNumbers ( ) {
36
+ let sum = 0 ;
37
+ let userInput = parseFloat ( document . getElementById ( 'input-number' ) . value ) ;
38
+ if ( userInput >= 1 & userInput <= 100 ) {
39
+ for ( var i = 0 ; i <= userInput ; i ++ ) {
40
+ if ( i % 2 === 0 ) {
41
+ sum += i ;
42
+ }
43
+ }
44
+ document . getElementById ( 'final-result' ) . innerHTML = "The sum of even numbers between 0 and " + userInput + " is " + sum + "." ;
45
+ } else {
46
+ document . getElementById ( 'final-result' ) . innerHTML = "Please provide the number between 1 and 100!"
47
+ }
48
+ }
49
+
50
+
51
+ </ script >
52
+ </ body >
53
+ </ html >
You can’t perform that action at this time.
0 commit comments