File tree 1 file changed +9
-4
lines changed
1 file changed +9
-4
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ function App() {
21
21
const [ result , setResult ] = useState ( [ ] ) ;
22
22
const [ input , setInput ] = useState ( '' ) ;
23
23
24
+ let alertVariant = 'primary' ;
25
+
24
26
const handleInputChange = ( event ) => {
25
27
setInput ( event . target . value ) ;
26
28
} ;
@@ -39,9 +41,12 @@ function App() {
39
41
setLoading ( true ) ;
40
42
const r = binarySearch ( inputData , parseInt ( searchItem ) ) ;
41
43
if ( r [ 1 ] . length ) {
42
- r [ 0 ] > - 1
43
- ? setAlertMessage ( 'Element found on index ' + r [ 0 ] )
44
- : setAlertMessage ( 'Element cannot be found in the list' ) ;
44
+ if ( r [ 0 ] > - 1 ) {
45
+ setAlertMessage ( 'Element found on index ' + r [ 0 ] ) ;
46
+ } else {
47
+ setAlertMessage ( 'Element cannot be found in the list' ) ;
48
+ alertVariant = 'danger' ;
49
+ }
45
50
}
46
51
setLoading ( false ) ;
47
52
setResult ( r ) ;
@@ -82,7 +87,7 @@ function App() {
82
87
{ loading && < ProgressBar animated now = { 100 } /> }
83
88
</ form >
84
89
{ alertMessage && (
85
- < Alert variant = "primary" className = "mb-5" >
90
+ < Alert variant = { alertVariant } className = "mb-5" >
86
91
{ ' ' }
87
92
{ alertMessage } { ' ' }
88
93
</ Alert >
You can’t perform that action at this time.
0 commit comments