1
00:00:02,029 --> 00:00:06,530
Now, that we learned about this new EJS syntax

2
00:00:06,530 --> 00:00:10,520
that helps us with, for example, writing a "for loop",

3
00:00:10,520 --> 00:00:14,040
we can use that same syntax to also output content

4
00:00:14,040 --> 00:00:15,960
conditionally,

5
00:00:15,960 --> 00:00:19,730
because that's something else you often want to do.

6
00:00:19,730 --> 00:00:23,080
Sometimes, you have different circumstances that influence

7
00:00:23,080 --> 00:00:25,180
which content should be shown.

8
00:00:25,180 --> 00:00:30,080
For example, let's say here, what if we had no restaurants?

9
00:00:30,080 --> 00:00:33,307
What if I temporarily cut all the restaurants in there

10
00:00:33,307 --> 00:00:36,820
so that I have an empty array again,

11
00:00:36,820 --> 00:00:38,523
and I saved this Jason file.

12
00:00:39,620 --> 00:00:43,020
Then at the moment we say "We found 0 restaurants",

13
00:00:43,020 --> 00:00:45,230
and we don't show any list.

14
00:00:45,230 --> 00:00:46,240
It's not too bad,

15
00:00:46,240 --> 00:00:49,480
but we also show "Find your next favorite restaurant",

16
00:00:49,480 --> 00:00:53,050
and we might overall want to show a different message in

17
00:00:53,050 --> 00:00:56,853
case that there are no restaurants at all at this point.

18
00:00:58,170 --> 00:01:01,968
And to do that, we can go back to "restaurants.EJS",

19
00:01:01,968 --> 00:01:04,400
and again, use this syntax,

20
00:01:04,400 --> 00:01:06,923
but this time for an "if" statement.

21
00:01:07,810 --> 00:01:11,260
And if I want to show these paragraphs and this list,

22
00:01:11,260 --> 00:01:13,380
only if we have restaurants,

23
00:01:13,380 --> 00:01:16,140
then we can add a "if" statement here.

24
00:01:16,140 --> 00:01:18,440
Here without the equal sign because again,

25
00:01:18,440 --> 00:01:20,330
we don't want to output a single value,

26
00:01:20,330 --> 00:01:23,363
but write a more complex JavaScript statement.

27
00:01:24,390 --> 00:01:27,410
And here we can then say if,

28
00:01:27,410 --> 00:01:28,437
and then simply check

29
00:01:28,437 --> 00:01:31,297
"if number of restaurants is equal to 0",

30
00:01:31,297 --> 00:01:35,580
and if that's the case, then we want to do something.

31
00:01:35,580 --> 00:01:38,700
Don't forget the opening parentheses "else",

32
00:01:38,700 --> 00:01:39,958
we want to do something else.

33
00:01:39,958 --> 00:01:43,470
So for this, we can then close the "if" block here.

34
00:01:43,470 --> 00:01:47,181
And also if we want to add an "else" or "else if" statement,

35
00:01:47,181 --> 00:01:51,490
in my case, "else", and open a new block,

36
00:01:51,490 --> 00:01:55,723
and then also close this block here at some point.

37
00:01:57,790 --> 00:02:01,490
So that's how we could write that "if else", statement.

38
00:02:01,490 --> 00:02:03,280
And now I want to output a special message

39
00:02:03,280 --> 00:02:05,350
if we have no restaurants.

40
00:02:05,350 --> 00:02:06,917
For example, I want to say,

41
00:02:06,917 --> 00:02:11,737
"Unfortunately, we have no restaurants yet,

42
00:02:12,970 --> 00:02:16,447
maybe start recommending some?"

43
00:02:17,820 --> 00:02:19,417
Anything like that.

44
00:02:19,417 --> 00:02:22,270
"Else", if number of restaurants is greater than zero,

45
00:02:22,270 --> 00:02:25,630
we want to show our restaurants and these paragraphs.

46
00:02:25,630 --> 00:02:28,039
So then I'll grab all that code here

47
00:02:28,039 --> 00:02:29,500
with the other of lists.

48
00:02:29,500 --> 00:02:33,933
and the paragraphs, and dragged that into this block here.

49
00:02:36,950 --> 00:02:37,983
Just like that.

50
00:02:39,310 --> 00:02:42,190
And now with that, if I save this and I reload,

51
00:02:42,190 --> 00:02:45,160
I get this message because I deleted the restaurants

52
00:02:45,160 --> 00:02:46,960
from the Jason file.

53
00:02:46,960 --> 00:02:49,320
If I go back to the Jason file

54
00:02:49,320 --> 00:02:52,270
and I re-add those restaurants here,

55
00:02:52,270 --> 00:02:54,120
and I saved that file.

56
00:02:54,120 --> 00:02:55,486
Now if I reload,

57
00:02:55,486 --> 00:02:58,803
I instead get my other text and that list.

58
00:02:59,700 --> 00:03:03,270
So conditional statements are another key feature,

59
00:03:03,270 --> 00:03:06,880
and thanks to this special EJS syntax we learned about

60
00:03:07,984 --> 00:03:10,000
with this tag here,

61
00:03:10,000 --> 00:03:13,103
it's very easy to add that kind of feature.

