@@ -11,7 +11,7 @@ var svg,
1111 unsortedColor = "#add8e6" ,
1212 sortedColor = "green" ,
1313 isSorting = false ,
14- isSorted = false ;
14+ isFound = false ;
1515
1616var swooshAudio = new Audio ( "./../sound-effects/swoosh.mp3" ) ;
1717var completeAudio = new Audio ( "./../sound-effects/complete.mp3" ) ;
@@ -63,7 +63,7 @@ const SearchAlgo = {
6363
6464 completeAudio . play ( ) ;
6565 isSorting = false ;
66- isSorted = true ;
66+ isFound = true ;
6767 }
6868
6969 // calling async function here
@@ -88,7 +88,9 @@ const SearchAlgo = {
8888 changeBarColor ( data [ mid ] , traverseColor ) ;
8989 if ( data [ mid ] == target ) {
9090 changeBarColor ( data [ mid ] , sortedColor ) ;
91- console . log ( "found" ) ;
91+ isFound = true ;
92+ let text = target + " Found at position " + ( mid + 1 ) ;
93+ document . getElementById ( "foundNotice" ) . innerHTML = text ;
9294 await timer ( time ) ;
9395 break ;
9496 } else if ( data [ mid ] < target ) {
@@ -100,12 +102,15 @@ const SearchAlgo = {
100102
101103 await timer ( time ) ;
102104 }
105+ if ( ! isFound ) {
106+ document . getElementById ( "foundNotice" ) . innerHTML =
107+ target + " doesn't exist." ;
108+ }
103109
104110 // after complete sorting complete making all the bar green and playing complete sound effects
105111
106112 completeAudio . play ( ) ;
107113 isSorting = false ;
108- isSorted = true ;
109114 }
110115
111116 // calling async function here
@@ -114,7 +119,7 @@ const SearchAlgo = {
114119} ;
115120
116121function startSearching ( ) {
117- algo = document . getElementById ( "get-algo" ) . value ;
122+ let algo = document . getElementById ( "get-algo" ) . value ;
118123 if ( algo == "linear-search" ) {
119124 const linearSearchStarted = SearchAlgo . liearSearch . bind ( SearchAlgo ) ;
120125 linearSearchStarted ( ) ;
0 commit comments