Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,240 --> 00:00:00,570
All right.
2
00:00:00,570 --> 00:00:03,630
So here comes the answer to challenge 1.
3
00:00:03,750 --> 00:00:08,730
If you've already completed challenge 1 and you just want to see how it's done then continue watching
4
00:00:08,730 --> 00:00:09,500
the video.
5
00:00:09,840 --> 00:00:14,820
If you've gone through all of the hints and you're still stuck and you really don't know what to do
6
00:00:15,150 --> 00:00:18,420
then also keep playing and I'll show you the answer.
7
00:00:18,450 --> 00:00:24,460
But if you still want to keep trying then pause the video before I reveal the answer.
8
00:00:24,480 --> 00:00:25,470
All right here we go.
9
00:00:25,650 --> 00:00:27,050
So inside our home.
10
00:00:27,220 --> 00:00:27,610
ejs,
11
00:00:27,630 --> 00:00:33,510
we're going to create that h1 that just says home. And then we're going to go into our app.js
12
00:00:33,810 --> 00:00:37,130
which is our server code to try and render that page.
13
00:00:37,320 --> 00:00:40,760
And the route that we're going to target is going to be the home route.
14
00:00:40,830 --> 00:00:46,440
So we're going to say app.get and we're going to target the home route or the root route.
15
00:00:46,530 --> 00:00:48,590
That's the one that's just the /.
16
00:00:48,710 --> 00:00:55,140
And then we're going to put in a callback function with our req and res as per usual.
17
00:00:55,560 --> 00:01:00,790
And then inside this function is where we're going to render our home.ejs.
18
00:01:00,900 --> 00:01:08,790
And if you remember the method for that using Express is res.render and then we specify what it is
19
00:01:08,790 --> 00:01:10,070
that we want to render.
20
00:01:10,230 --> 00:01:16,830
And remember the page that we want to render has to be something.ejs and it has to be inside a folder
21
00:01:16,830 --> 00:01:20,800
called views in the root of our main project folder
22
00:01:21,120 --> 00:01:25,550
in the same hierarchical level as app.js.
23
00:01:25,740 --> 00:01:29,230
Now the page that we want to render in this case is home.ejs
24
00:01:29,370 --> 00:01:37,140
so all we have to specify is the string home inside a set of quotation marks. And then we'll close everything
25
00:01:37,140 --> 00:01:39,180
off with some semi-colons.
26
00:01:39,180 --> 00:01:46,230
So now if we hit Save and we make sure that we're inside our ejs-challenge folder then we're going
27
00:01:46,230 --> 00:01:54,020
to use nodemon to start our app.js and run our server. So service starts on port 3000
28
00:01:54,090 --> 00:01:56,700
I'm going to head over to localhost:3000
29
00:01:56,970 --> 00:02:02,530
and this is how we achieve the goal for Challenge 1.
30
00:02:02,540 --> 00:02:07,280
Now if you manage to get here without needing any of the hints then that's a huge pat on the back and
31
00:02:07,280 --> 00:02:08,710
a gold star for you.
32
00:02:08,960 --> 00:02:13,460
Now if you needed to have a look at a few of the hints then that's fine as well.
33
00:02:13,460 --> 00:02:19,860
See if in the coming challenges you can reduce the number of hints you need and rely more on Sstack Overflow
34
00:02:19,860 --> 00:02:25,910
or Google to achieve what it is that you want instead of looking at the hints or the answers. And only
35
00:02:25,910 --> 00:02:31,690
use them when you're well and truly stuck and you can't move forwards without watching a hint or two.
36
00:02:31,880 --> 00:02:37,140
So that's all for challenge 1. In the next video we're going to head over to the next challenge.
3727
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.