Tour of CoderPad
- [Instructor] This course includes automated code challenges that appear when you click on the challenge links in the course's table of contents. Each challenge includes instructions and a couple of code editors you can use to create and test your own solution to the challenge. These challenges are hosted by CoderPad, and they appear in the same area of the course page where you watch the course's videos. We recommend using a desktop browser for the best experience with these code challenges, but you can also use the LinkedIn Learning mobile app, if you prefer. The code Challenge has four areas. The Instructions in the top left, a code editor for your answer in the top right, another code editor where you can see how your code is used in the bottom right, and a console for output in the bottom left. You can use these drag handles to allocate space as needed. Let me show you an example. If I pull this over, I can now see more of the Answer and Test code. Each challenge has instructions that include a description of the challenge and any parameters that the challenge needs, as well as the desired result. You create your own answer in the top right code editor. There are comments in the starting code, showing where to put your solution. When you click Test my code, you'll see a message indicating whether your code returned a correct result. So, let's go ahead and run this. And you can see, right now, I did not get the correct result. It says, "Whoops, that's not it! Consider revisiting the question." So, let's go back over here to our answer code. Well, that's because we didn't fill in our answer yet. Let's go ahead and change that. I'm going to put the code here where it says, "Your code goes here." I'm going to say return Arrays.stream, and then I'm going to send the stream the numbers array, .max, which will find the largest value in the array. And then the last thing is I want to get it as an integer. So, getAsInt. All right, I don't need to return the zero anymore, so I'll comment that line out. Let's go ahead and test my code. It looks like I have another error. It says, "Cannot find symbol." Well, that's because I did not import the library that I need for the Arrays. Let's go back into our code. And on line 4, I'm going to add import java.util.Arrays. And I'm going to run it again. Test my code. All right, another one solved. We got a return code of 19. And if we look in the bottom where it shows the code that we're using to test our code, you'll see the numbers were 7, 17, 13, 19, and 5. So, 19 is the largest number in that series. But what happens when your code is not successful? The show expected results and show hints variables define whether you will see the expected results or any hints. Let's change those to true. So, up here on line 9, I'm going to change it from false to true. And on line 10, the same thing. And then I'm going to change it so that it does not return the right value. So, let's go ahead and have it return the value, I'll just go back to returning zero. All right, let's test our code. Notice, in the Console output, this time, it does say, "Incorrect. Try again." It says that I returned a zero. And right below that it says, "Need help?" It says the expected result was 19. And it gives you a hint. You can either iterate through the entire array and do your own calculation to find the largest number, or you can use a Java stream. Okay, I'm going to go ahead and put the correct answer back in. And now it's always a good idea to do some additional testing. So, in my test code down the bottom, let's see what happens if all of these numbers are negative. The largest numbers of a series of negative numbers is going to be the smallest one. So, hopefully, it'll say -5. And you can see in the Console output, it says, "Correct! Marvelous work. Your code returned: -5." Well, that's awesome. So, that worked. You can change that code to do any number of different tests. Regardless of whether your answer is successful, you'll see messages in the Console output in the lower left. If any messages are too long to fit in the area, you can scroll sideways to see all of the text. When you finished each code challenge, return to the course's table of contents and click the next video to see my solution.