Skip to content
Playback Speed:
Transcript

In this video, you will insert breakpoints in your code to test the “words” array.

Then, you will test sections of your code to be sure that your values are correctly stored in the “words” array.

To see if your array is working as you expect, check it for errors, or debug it.

Debugging keeps you from having to add a lot of logging statements to your code.

To debug, first set a “breakpoint” in your code.

A breakpoint allows you to check specific lines of code.

The program pauses the code at each breakpoint, so you can see what is happening.

Click the number of the line that contains the “words” array.

A red dot appears.

This is the first breakpoint.

Then, click the number of the line with the findText instructions.

This is the second breakpoint.

Now, the program will pause at each of these points and read your code in sections.

Test your code.

Select the “highlightProblem” function.

Then, instead of clicking the “Run” button, click “Debug.”

A debugging window appears at the bottom of the screen.

The code runs until it reaches the first breakpoint, before the highlighted code.

The debug window shows that the array “words” is empty, or undefined, at this point.

The array has not yet run.

Click “Continue” to advance the code to the next breakpoint.

This time, the debugging window shows that the array “words” contains the values you added.

This line tells the computer to search for all of the values in the array.

They are listed as values 0, 1, 2, 3, and so on.

Great!

This one line stores all the values the program will search for.

Now that you know your array is working, remove the breakpoints.

Programmers sometimes write code that is millions of lines long!

Adding comments and breakpoints, and debugging sections of code, is essential when working with any project--large or small!

Now, it’s your turn: Add breakpoints to your code.

Then, debug two sections of your program to test that your values are correctly stored in the “words” array.

When your program searches for all the words in the array, move on to the next video, where you will use the array to highlight all of the words stored in it.

Next arrow_forward
Instructions
  1. Add two breakpoints to your code.
  2. Debug two sections of your program to test that your values are correctly stored in the “words” array.