File tree Expand file tree Collapse file tree 1 file changed +9
-2
lines changed
Expand file tree Collapse file tree 1 file changed +9
-2
lines changed Original file line number Diff line number Diff line change 9393 inputField . stringToEval += inputField . currentValue ;
9494
9595 // Append number to string to make a multi digit number
96- } else if ( numbers . has ( inputField . previousValue ) ) {
96+ } else if ( numbers . has ( inputField . previousValue ) || decimal . has ( inputField . previousValue ) ) {
9797 // Append the number clicked to the display
9898 inputField . display += inputField . currentValue ;
99+ inputField . stringToEval += inputField . currentValue ;
99100 }
100101 } else if ( operators . has ( inputField . currentValue ) ) {
101102 // - **Operators**: if a user clicks on an operator:
116117 // - append a decimal to string
117118 // - but only if the previous value is a number
118119 // - and not if there is already a decimal in the string
120+ if ( ( numbers . has ( inputField . previousValue ) || equals . has ( inputField . previousValue ) ) && ! inputField . display . includes ( '.' ) ) {
121+ // Append the decimal to the display
122+ inputField . display += inputField . currentValue ;
123+ // Append the decimal to the string to evaluate
124+ inputField . stringToEval += inputField . currentValue ;
125+ }
119126
120127 } else if ( clear . has ( inputField . currentValue ) ) {
121128 // - **Clear**: if a user clicks on clear:
144151 display . textContent = inputField . display ;
145152
146153 // Print to console for debugging
147- console . log ( `Before button logic: ${ JSON . stringify ( inputField ) } ` ) ;
154+ console . log ( `After button logic: ${ JSON . stringify ( inputField ) } ` ) ;
148155 } ) ;
149156 } ) ;
150157 } ) ;
You can’t perform that action at this time.
0 commit comments