0 1 00:00:00,290 --> 00:00:02,950 Are you ready for challenge 11? 1 2 00:00:03,210 --> 00:00:12,540 Now in this challenge I want you to put this newly created post object inside a global variable called 2 3 00:00:12,750 --> 00:00:15,780 posts, with an 's' at the end. 3 4 00:00:15,790 --> 00: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 5 00:00:22,590 --> 00:00:23,800 variable. 5 6 00:00:23,880 --> 00: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 7 00:00:30,000 --> 00:00:32,670 post object to that new array. 7 8 00:00:33,000 --> 00:00:41,160 And finally at the end of this route you're going to redirect to the root route. And inside the 8 9 00:00:41,160 --> 00:00:48,570 root route we're going to log all of the posts inside the post array that you created. 9 10 00:00:48,660 --> 00:00:56,190 Once you've completed this, what should happen is I should be able to put in a post hit publish 10 11 00:00:56,340 --> 00:01:04,500 and then let's go back to compose again and let's put in another post and hit publish. 11 12 00:01:04,650 --> 00:01:10,420 And firstly you notice that we get directed to the root route or the home page 12 13 00:01:10,530 --> 00: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 14 00:01:18,390 --> 00:01:20,850 my entire array is being logged 14 15 00:01:21,060 --> 00:01:27,540 and the first time it only contained a single object, the 'Day 1 post, and the second time this array 15 16 00:01:27,540 --> 00:01:33,690 contained two Javascript objects both of my posts, 'Day 1' and 'Day 2'. 16 17 00:01:33,900 --> 00:01:42,730 This is the end goal of this challenge and it's time to pause the video and tackle this challenge. 17 18 00:01:42,740 --> 00:01:44,380 All right so here's my first hint. 18 19 00:01:45,260 --> 00: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 20 00:01:53,360 --> 00:01:54,410 route. 20 21 00:01:54,530 --> 00:01:58,290 Now in order to do that we need a global variable. 21 22 00:01:58,490 --> 00:02:04,850 Remember that global variables have to be declared outside of all of the other functions in the page. 22 23 00:02:05,060 --> 00:02:08,940 So that means you probably have to do it somewhere up here 23 24 00:02:09,080 --> 00:02:13,610 outside of all of the other functions and routes. 24 25 00:02:13,650 --> 00:02:18,360 All right so here's hint number 2. In order to create an empty array 25 26 00:02:18,540 --> 00:02:21,480 you will need to write something like this. 26 27 00:02:21,480 --> 00: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 28 00:02:28,290 --> 00:02:34,950 empty array and assign it to this variable by saying = 28 29 00:02:34,980 --> 00:02:42,180 [ ] ; and this would be an empty array that has nothing inside until we add something 29 30 00:02:42,180 --> 00:02:42,740 to it. 30 31 00:02:44,840 --> 00: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 32 00:02:53,810 --> 00:03:01,370 we're going to need to use something called res.redirect. And this is a method that allows you 32 33 00:03:01,370 --> 00:03:04,100 to redirect to another route, 33 34 00:03:04,160 --> 00:03:10,640 so essentially make a get request on any of the other routes. And if you wanted to redirect and inside 34 35 00:03:10,760 --> 00:03:15,830 the parentheses you would put the route that you want to redirect to. 35 36 00:03:15,860 --> 00:03:20,730 Those are all of my hints and see if now you can complete this challenge successfully.