File tree 3 files changed +73
-0
lines changed
3 files changed +73
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!doctype html>
2
+ < html >
3
+ < head >
4
+ < title >
5
+ A mini calculator
6
+ </ title >
7
+ < link rel ="stylesheet " href ="style.css " type ="text/css ">
8
+ </ head >
9
+ < body >
10
+ < span id ="num1-el "> </ span >
11
+ < span id ="num2-el "> </ span >
12
+ < br >
13
+ < button onclick ="add() "> Add</ button >
14
+ < button onclick ="subtract() "> Subtract</ button >
15
+ < button onclick ="divide() "> Divide</ button >
16
+ < button onclick ="multiply() "> Multiply</ button >
17
+ < br >
18
+ < span id ="sum-el "> Sum: </ span >
19
+ < script src ="index.js "> </ script >
20
+ </ body >
21
+ </ html >
Original file line number Diff line number Diff line change
1
+ //@ts -check
2
+
3
+ let num1 = 8 ;
4
+ let num2 = 2 ;
5
+
6
+ // Extracting the elements
7
+ num1EL = document . getElementById ( "num1-el" ) ;
8
+ num2EL = document . getElementById ( "num2-el" ) ;
9
+
10
+ num1EL . textContent = num1 ;
11
+ num2EL . textContent = num2 ;
12
+
13
+ function add ( ) {
14
+ let sum = num1 + num2 ;
15
+ document . getElementById ( "sum-el" ) . textContent = "Sum: " + sum ;
16
+ }
17
+
18
+ function subtract ( ) {
19
+ let diff = num1 - num2 ;
20
+ document . getElementById ( "sum-el" ) . textContent = "Difference: " + diff ;
21
+ }
22
+
23
+ function divide ( ) {
24
+ let div = num1 / num2 ;
25
+ document . getElementById ( "sum-el" ) . textContent = "Division: " + div ;
26
+ }
27
+
28
+ function multiply ( ) {
29
+ let prod = num1 * num2 ;
30
+ document . getElementById ( "sum-el" ) . textContent = "Multiply: " + prod ;
31
+ }
Original file line number Diff line number Diff line change
1
+ body {
2
+ font-family : Arial, Helvetica, sans-serif;
3
+ padding : 20px 0 ;
4
+ margin : 0 ;
5
+ text-align : center;
6
+ }
7
+
8
+ span {
9
+ border-bottom : 2px solid black;
10
+ padding : 4px ;
11
+ }
12
+
13
+ button {
14
+ margin : 20px 0 ;
15
+ background : white;
16
+ color : black;
17
+ border : 1px solid black;
18
+ font-weight : bold;
19
+ cursor : pointer;
20
+ padding : 5px 8px ;
21
+ }
You can’t perform that action at this time.
0 commit comments