@@ -2,8 +2,19 @@ const loadFoods = () => {
2
2
document . getElementById ( 'preloader' ) . style . display = 'block' ;
3
3
const inputField = document . getElementById ( 'input-field' ) ;
4
4
const inputFieldValue = inputField . value ;
5
+ if ( ! inputFieldValue ) {
6
+ alert ( 'Write something.............' ) ;
7
+ document . getElementById ( 'preloader' ) . style . display = 'none' ;
8
+ return ;
9
+ }
10
+ else if ( inputFieldValue < 0 ) {
11
+ alert ( 'Enter positive number' ) ;
12
+ document . getElementById ( 'preloader' ) . style . display = 'none' ;
13
+ return ;
14
+ }
5
15
6
16
document . getElementById ( 'display-search-result' ) . innerHTML = '' ;
17
+ document . getElementById ( 'no-search-result' ) . style . display = 'none' ;
7
18
document . getElementById ( 'main' ) . style . display = "none" ;
8
19
document . getElementById ( 'footer' ) . style . display = "none" ;
9
20
fetch ( `https://www.themealdb.com/api/json/v1/1/search.php?s=${ inputFieldValue } ` )
@@ -14,6 +25,10 @@ const loadFoods = () => {
14
25
}
15
26
16
27
const displayFoods = foods => {
28
+ if ( ! foods ) {
29
+ document . getElementById ( 'no-search-result' ) . style . display = 'block' ;
30
+ document . getElementById ( 'preloader' ) . style . display = 'none' ;
31
+ }
17
32
console . log ( foods ) ;
18
33
// document.getElementById('display-search-result').innerHTML = '';
19
34
const searchResult = document . getElementById ( 'display-search-result' ) ;
@@ -31,6 +46,7 @@ const displayFoods = foods => {
31
46
searchResult . appendChild ( div ) ;
32
47
} )
33
48
document . getElementById ( 'preloader' ) . style . display = 'none' ;
49
+ document . getElementById ( 'no-search-result' ) . style . display = 'none' ;
34
50
}
35
51
36
52
const loadFoodDetails = foodId => {
@@ -47,7 +63,7 @@ const getFoodDetails = food => {
47
63
<img src="${ food . strMealThumb } ">
48
64
<h4>${ food . strMeal } </h4>
49
65
<p>${ food . strInstructions } </p>
50
- <button><a href="${ food . strYoutube } " target="_blank">Visit Youtube</a></button>
66
+ <button><a href="${ food . strYoutube } " target="_blank">Watch in Youtube</a></button>
51
67
52
68
</div>
53
69
0 commit comments