1 00:00:00,580 --> 00:00:02,450 This challenge should have been pretty easy. 2 00:00:02,450 --> 00:00:05,800 You already learned how to create a random number between two values in 3 00:00:05,800 --> 00:00:07,570 stage three of this course. 4 00:00:07,570 --> 00:00:12,070 However, now you're using a function that accepts arguments. 5 00:00:12,070 --> 00:00:13,230 I didn't put anything but 6 00:00:13,230 --> 00:00:17,530 the formula in the random.js file, so you had to remember how to create a function. 7 00:00:20,480 --> 00:00:24,240 Because the function should produce a random value between two numbers, 8 00:00:24,240 --> 00:00:26,420 we need to add two parameters to the function. 9 00:00:29,190 --> 00:00:33,690 Then I'll just move the formula into our function and 10 00:00:33,690 --> 00:00:36,870 place the parameters where they need to go. 11 00:00:36,870 --> 00:00:42,840 The upper value goes here, and the lower value is here, and here. 12 00:00:45,170 --> 00:00:46,880 I'll assign the result to a variable. 13 00:00:49,990 --> 00:00:53,130 Then we'll return that variable and exit the function. 14 00:00:56,350 --> 00:00:58,780 You can make this code even more compact. 15 00:00:58,780 --> 00:01:03,090 You don't need to assign the formula to a variable and then return the variable. 16 00:01:03,090 --> 00:01:05,510 Because the formula produces a value, 17 00:01:05,510 --> 00:01:08,740 you can simply return the results of the formula like this. 18 00:01:10,730 --> 00:01:12,260 Why can you do this? 19 00:01:12,260 --> 00:01:13,510 Well, let's look at this formula. 20 00:01:13,510 --> 00:01:16,460 It takes some information, the two variables and 21 00:01:16,460 --> 00:01:20,100 runs it through a couple of JavaScript methods and does some math. 22 00:01:20,100 --> 00:01:25,330 All of this code evaluates, as programmers say, to a single value, the random number. 23 00:01:26,690 --> 00:01:29,740 All a return statement does is return a value. 24 00:01:29,740 --> 00:01:32,520 It doesn't matter where that value comes from. 25 00:01:32,520 --> 00:01:36,980 It can be stored in a variable, or it can just be the result of another function, or 26 00:01:36,980 --> 00:01:39,680 some mathematical operations, as it is in this case. 27 00:01:40,740 --> 00:01:42,780 Okay, now it's time to test this. 28 00:01:43,850 --> 00:01:47,472 I'll just call the function a few times, and 29 00:01:47,472 --> 00:01:51,011 print the results to the console each time. 30 00:01:51,011 --> 00:02:01,011 [BLANK_AUDIO] 31 00:02:08,395 --> 00:02:12,320 I'll save the file and preview the work space. 32 00:02:14,400 --> 00:02:15,290 I'll open the console. 33 00:02:16,500 --> 00:02:18,510 Looking good, some random numbers. 34 00:02:18,510 --> 00:02:19,880 I'll reload. 35 00:02:19,880 --> 00:02:21,010 More random numbers. 36 00:02:21,010 --> 00:02:24,990 And you can see they're between the values that I specified in my code. 37 00:02:24,990 --> 00:02:28,720 As you'll see in the next video, however, there is a problem with this function. 38 00:02:28,720 --> 00:02:29,750 And you'll need to fix it.