File tree Expand file tree Collapse file tree 2 files changed +32
-2
lines changed
Expand file tree Collapse file tree 2 files changed +32
-2
lines changed Original file line number Diff line number Diff line change 3333 position : absolute;
3434 height : 530px ;
3535 width : 400px ;
36- border : black 1px solid;
37- border-radius : 15px ;
36+
3837 overflow : hidden;
3938 display : grid;
4039 grid-template-columns : repeat (4 , 1fr );
Original file line number Diff line number Diff line change @@ -10,6 +10,37 @@ const clearHistoryBtn = document.querySelector(".clear-history-btn");
1010clearHistoryBtn . addEventListener ( "click" , ( ) => { historyElement . innerHTML = "" ;
1111} ) ;
1212
13+ document . addEventListener ( 'keydown' , handleKeyPress ) ;
14+
15+ function handleKeyPress ( event ) {
16+
17+ const key = event . key ;
18+ const button = document . querySelector ( `[data-value="${ key } "]` ) ;
19+
20+ console . log ( key )
21+
22+
23+
24+ if ( button ) {
25+ button . click ( ) ; // Trigger the click event for the corresponding button
26+ }
27+
28+ if ( event . code === "Backspace" ) {
29+ let newArray = data . slice ( ZERO , - 1 ) ;
30+ screen . innerText = newArray . join ( "" ) ;
31+ data = newArray ;
32+ if ( screen . innerText === "" ) {
33+ screen . innerText = ZERO ;
34+ }
35+ }
36+
37+ if ( event . code === "Enter" ) {
38+ userClicksOnEqualButton ( "=" ) ;
39+ }
40+
41+ }
42+
43+
1344const operatorRegex = / [ \/ * \- + ] / ;
1445const ZERO = 0 ;
1546const ZERO_DOT = "0." ;
You can’t perform that action at this time.
0 commit comments