File tree Expand file tree Collapse file tree 1 file changed +28
-5
lines changed
05-javascript-a-ds-new/2-advanced-javascript/2d-learn-recursion-by-building-binary-converter Expand file tree Collapse file tree 1 file changed +28
-5
lines changed Original file line number Diff line number Diff line change 454454## 🟥 Making Stack Animation
455455* I want to show an animation of how ` 5 ` is converted to it's binary input using an animation
456456* I create a new function to show the animation:
457- ``` js
458- const showAnimation = () => {}
459- ```
457+ ``` js
458+ const showAnimation = () => {}
459+ ```
460460* And then I call this function and return early, in checkUserInput, when input is 5:
461- ``` js
461+ ``` js
462462 const checkUserInput = () => {
463463 // CHECK USER INPUT LOGIC
464464
@@ -468,4 +468,27 @@ const showAnimation = () => {}
468468 }
469469 // REST OF CODE
470470 };
471- ```
471+ ```
472+
473+ ### 🔺 Refactoring checkUserInput() 🔺
474+ * My ` checkUserInput ` function has loads of duplication with parsing the user input:
475+ <details >
476+ <summary >checkUserInput()</summary >
477+
478+ ``` js
479+ const checkUserInput = () => {
480+ if (! numberInput .value || isNaN (parseInt (numberInput .value )) || parseInt (numberInput .value )< 0 ) {
481+ alert (" Please provide a decimal number greater than or equal to 0" );
482+ return ;
483+ }
484+
485+ if (parseInt (numberInput .value ) === 5 ) {
486+ showAnimation ();
487+ return ;
488+ }
489+
490+ result .textContent = decimalToBinary (parseInt (numberInput .value ))
491+ numberInput .value = ' '
492+ }
493+ ```
494+ </details >
You can’t perform that action at this time.
0 commit comments