WEBVTT 0 00:00.290 --> 00:02.950 Are you ready for challenge 11? 1 00:03.210 --> 00:12.540 Now in this challenge I want you to put this newly created post object inside a global variable called 2 00:12.750 --> 00:15.780 posts, with an 's' at the end. 3 00:15.790 --> 00:22.590 We're going to have an array that is going to store all of these new posts but it's going to be a global 4 00:22.590 --> 00:23.800 variable. 5 00:23.880 --> 00:30.000 You need to create a new empty array that is a global variable and then you're going to add this new 6 00:30.000 --> 00:32.670 post object to that new array. 7 00:33.000 --> 00:41.160 And finally at the end of this route you're going to redirect to the root route. And inside the 8 00:41.160 --> 00:48.570 root route we're going to log all of the posts inside the post array that you created. 9 00:48.660 --> 00:56.190 Once you've completed this, what should happen is I should be able to put in a post hit publish 10 00:56.340 --> 01:04.500 and then let's go back to compose again and let's put in another post and hit publish. 11 01:04.650 --> 01:10.420 And firstly you notice that we get directed to the root route or the home page 12 01:10.530 --> 01:18.390 once we've finished composing the post. And then if you take a look inside our terminal you can see that 13 01:18.390 --> 01:20.850 my entire array is being logged 14 01:21.060 --> 01:27.540 and the first time it only contained a single object, the 'Day 1 post, and the second time this array 15 01:27.540 --> 01:33.690 contained two Javascript objects both of my posts, 'Day 1' and 'Day 2'. 16 01:33.900 --> 01:42.730 This is the end goal of this challenge and it's time to pause the video and tackle this challenge. 17 01:42.740 --> 01:44.380 All right so here's my first hint. 18 01:45.260 --> 01:53.360 What we want to do is to be able to save this post object into an array which we can then log inside this home 19 01:53.360 --> 01:54.410 route. 20 01:54.530 --> 01:58.290 Now in order to do that we need a global variable. 21 01:58.490 --> 02:04.850 Remember that global variables have to be declared outside of all of the other functions in the page. 22 02:05.060 --> 02:08.940 So that means you probably have to do it somewhere up here 23 02:09.080 --> 02:13.610 outside of all of the other functions and routes. 24 02:13.650 --> 02:18.360 All right so here's hint number 2. In order to create an empty array 25 02:18.540 --> 02:21.480 you will need to write something like this. 26 02:21.480 --> 02:28.260 Let's say that we were creating a global var variable and we call it posts and then we would create an 27 02:28.290 --> 02:34.950 empty array and assign it to this variable by saying = 28 02:34.980 --> 02:42.180 [ ] ; and this would be an empty array that has nothing inside until we add something 29 02:42.180 --> 02:42.740 to it. 30 02:44.840 --> 02:53.750 All right so now this is my final hint and that is in order to move from the app.post to the apt.get 31 02:53.810 --> 03:01.370 we're going to need to use something called res.redirect. And this is a method that allows you 32 03:01.370 --> 03:04.100 to redirect to another route, 33 03:04.160 --> 03:10.640 so essentially make a get request on any of the other routes. And if you wanted to redirect and inside 34 03:10.760 --> 03:15.830 the parentheses you would put the route that you want to redirect to. 35 03:15.860 --> 03:20.730 Those are all of my hints and see if now you can complete this challenge successfully.