File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33 margin : 2rem auto;
44 background : white;
55 border-radius : 12px ;
6- box-shadow : 0 4px 8px rgba (0 , 0 , 0 , 0.1 );
6+ box-shadow : 0 4px 8px rgba (0 , 0 , 0 , 0.1 );
77 overflow : hidden;
88}
99
5050
5151.calc-buttons button : last-child : hover {
5252 background : # 059669 ;
53- }
53+ }
Original file line number Diff line number Diff line change 1- <!DOCTYPE html>
1+ <!doctype html>
22< html lang ="en ">
3- < head >
4- < meta charset ="UTF-8 ">
5- < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
6- < title > Calculator</ title >
7- < link rel ="stylesheet " href ="../css/style.css ">
8- < link rel ="stylesheet " href ="calculator.css ">
9- </ head >
10- < body >
11- < header >
12- < h1 > Calculator</ h1 >
13- < a href ="../index.html " class ="btn "> ← Back</ a >
14- </ header >
3+ < head >
4+ < meta charset ="UTF-8 " / >
5+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " / >
6+ < title > Calculator</ title >
7+ < link rel ="stylesheet " href ="../css/style.css " / >
8+ < link rel ="stylesheet " href ="calculator.css " / >
9+ </ head >
10+ < body >
11+ < header >
12+ < h1 > Calculator</ h1 >
13+ < a href ="../index.html " class ="btn "> ← Back</ a >
14+ </ header >
1515
16- < main class ="calc-container ">
17- < div class ="calc-screen " id ="screen "> 0</ div >
18- < div class ="calc-buttons ">
19- < button > C</ button >
20- < button > ←</ button >
21- < button > %</ button >
22- < button > /</ button >
16+ < main class ="calc-container ">
17+ < div class ="calc-screen " id ="screen "> 0</ div >
18+ < div class ="calc-buttons ">
19+ < button > C</ button >
20+ < button > ←</ button >
21+ < button > %</ button >
22+ < button > /</ button >
2323
24- < button > 7</ button >
25- < button > 8</ button >
26- < button > 9</ button >
27- < button > *</ button >
24+ < button > 7</ button >
25+ < button > 8</ button >
26+ < button > 9</ button >
27+ < button > *</ button >
2828
29- < button > 4</ button >
30- < button > 5</ button >
31- < button > 6</ button >
32- < button > -</ button >
29+ < button > 4</ button >
30+ < button > 5</ button >
31+ < button > 6</ button >
32+ < button > -</ button >
3333
34- < button > 1</ button >
35- < button > 2</ button >
36- < button > 3</ button >
37- < button > +</ button >
34+ < button > 1</ button >
35+ < button > 2</ button >
36+ < button > 3</ button >
37+ < button > +</ button >
3838
39- < button > 0</ button >
40- < button > .</ button >
41- < button > =</ button >
42- </ div >
43- </ main >
39+ < button > 0</ button >
40+ < button > .</ button >
41+ < button > =</ button >
42+ </ div >
43+ </ main >
4444
45- < script src ="calculator.js "> </ script >
46- </ body >
47- </ html >
45+ < script src ="calculator.js "> </ script >
46+ </ body >
47+ </ html >
Original file line number Diff line number Diff line change @@ -3,30 +3,27 @@ const buttons = document.querySelectorAll(".calc-buttons button");
33
44let current = "" ;
55
6- buttons . forEach ( btn => {
6+ buttons . forEach ( ( btn ) => {
77 btn . addEventListener ( "click" , ( ) => {
88 const value = btn . textContent ;
99
1010 if ( value === "C" ) {
1111 current = "" ;
1212 screen . textContent = "0" ;
13- }
14- else if ( value === "←" ) {
13+ } else if ( value === "←" ) {
1514 current = current . slice ( 0 , - 1 ) ;
1615 screen . textContent = current || "0" ;
17- }
18- else if ( value === "=" ) {
16+ } else if ( value === "=" ) {
1917 try {
2018 current = eval ( current ) . toString ( ) ;
2119 screen . textContent = current ;
2220 } catch {
2321 screen . textContent = "Error" ;
2422 current = "" ;
2523 }
26- }
27- else {
24+ } else {
2825 current += value ;
2926 screen . textContent = current ;
3027 }
3128 } ) ;
32- } ) ;
29+ } ) ;
You can’t perform that action at this time.
0 commit comments