Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,300 --> 00:00:00,630
All right.
2
00:00:00,630 --> 00:00:05,700
So at this stage you should have already downloaded the starting project and you would have installed
3
00:00:05,730 --> 00:00:07,939
all of the required NPM modules.
4
00:00:08,070 --> 00:00:13,230
If you haven't, make sure you take a look at the last lesson where we did this so that we're ready to
5
00:00:13,230 --> 00:00:14,250
proceed.
6
00:00:14,250 --> 00:00:18,980
Now once you're done then you're ready to tackle Challenge 1.
7
00:00:19,050 --> 00:00:25,280
So in order to complete challenge 1, you should be able to head over to localhost:3000
8
00:00:25,290 --> 00:00:33,540
and when you hit enter it should render the home page and it will have an h1 but just says Home.
9
00:00:33,750 --> 00:00:41,340
So in your home.ejs you'll need to create an h1 that says Home and by writing some code inside
10
00:00:41,370 --> 00:00:48,330
app.js, you should be able to get this to show up on localhost:3000.
11
00:00:48,360 --> 00:00:49,820
So that's Challenge 1.
12
00:00:49,860 --> 00:00:53,040
Pause the video and see if you can complete the challenge.
13
00:00:53,890 --> 00:00:59,410
All right so if you completed that challenge and you manage get the same result as I showed you when
14
00:00:59,410 --> 00:01:04,000
I introduced the challenge then that means you get a gold star for this challenge.
15
00:01:04,120 --> 00:01:08,400
Then you can skip the rest of this lesson and head over to the next lesson
16
00:01:08,410 --> 00:01:11,630
where I'll show you how I implemented the answer.
17
00:01:12,070 --> 00:01:18,070
Now if you're stuck on this challenge and you don't know how to proceed then after the spoiler alert
18
00:01:18,160 --> 00:01:20,520
there will be a five second countdown.
19
00:01:20,710 --> 00:01:26,380
Now you can either pause during the countdown, try and work out the challenge yourself or you can let
20
00:01:26,380 --> 00:01:29,710
the video play and I'll give you your first hint.
21
00:01:29,740 --> 00:01:31,250
So here comes the countdown.
22
00:01:35,670 --> 00:01:35,990
All right.
23
00:01:36,000 --> 00:01:38,830
So this is Hint number 1.
24
00:01:39,150 --> 00:01:42,450
So the first hint is we know that inside home.
25
00:01:42,660 --> 00:01:43,020
ejs
26
00:01:43,080 --> 00:01:49,210
we've got our h1. And this page is what we need to render from our server.
27
00:01:49,500 --> 00:01:55,320
So the place where we normally write our routes and where we render our EJS pages is between the app
28
00:01:55,320 --> 00:01:58,290
.set app.use and our app.listen.
29
00:01:58,290 --> 00:02:03,080
So we've got a gap right here that's already prepared for you to add your code.
30
00:02:03,120 --> 00:02:11,580
Now if you're remember, we create routes inside our server by saying app.get. And then we specify
31
00:02:11,790 --> 00:02:17,400
what route we want to target and then we add a callback function
32
00:02:17,430 --> 00:02:27,530
so a req and a res. And we open up a set of curly braces and inside the set of curly braces is where
33
00:02:27,530 --> 00:02:30,140
we render our Web page.
34
00:02:30,140 --> 00:02:36,530
So have a think about what you need to put in between these quotation marks in order to render the home
35
00:02:36,530 --> 00:02:40,590
page and then have a think about what you need to write inside here
36
00:02:40,790 --> 00:02:43,730
in order to render our home.ejs.
37
00:02:44,150 --> 00:02:51,320
So pause the video now and use that hint to complete the challenge. Still stuck?
38
00:02:51,540 --> 00:02:52,020
OK.
39
00:02:52,040 --> 00:02:54,070
Here's hint number 2.
40
00:02:54,400 --> 00:03:01,070
In between the quotation marks we need to specify the route that we want to target. And in our case we
41
00:03:01,070 --> 00:03:05,190
need to target the home route or what's known as the root route.
42
00:03:05,240 --> 00:03:11,770
So when we have something like "www.facebook.com/", that is the root route.
43
00:03:11,810 --> 00:03:15,020
So in our case that's just localhost:3000.
44
00:03:15,050 --> 00:03:21,800
So that means inside here, all we have to write is just a single forward slash to specify that we want
45
00:03:21,800 --> 00:03:23,960
to target this route.
46
00:03:24,250 --> 00:03:29,300
Now inside our app.get is where we're going to render our home.
47
00:03:29,520 --> 00:03:30,400
ejs.
48
00:03:30,440 --> 00:03:32,630
And the method for that is res.
49
00:03:32,660 --> 00:03:38,960
So this is the result that we are going to send back from the server to the user who's requesting this
50
00:03:38,960 --> 00:03:46,660
page and we're going to use the render method that Express gives us to be able to render our home.
51
00:03:46,700 --> 00:03:47,700
ejs.
52
00:03:48,170 --> 00:03:54,500
So have a think about what else you might need to put in between those parentheses in order to get this
53
00:03:54,500 --> 00:03:55,710
code to work.
54
00:03:55,880 --> 00:04:01,910
Have a play around with the code and pause the video now to see if you can now complete the challenge.
5340
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.