Comp 110 Debugging Help

Fixing the "Black Screen of Death"

When you see the error below, there are a few things to note!

  1. Check which file the error is in! (It may be the one that isn't currently open)...follow the file path in the first line
  2. Try commenting out all of the code in that file and saving
    1. CTRL + A (select all)
    2. CTRL + / (comment out)
    3. CTRL + S (save)
  3. Typescript THINKS that the error is on the line given
    1.  For example, line check that line

One of My Functions Isn't Working!...But it's right?

This is a good opportunity to practice tracing code. If you are sure that a function is correct, but it is not returning the proper values, check ALL of the functions that are CALLED within the original function!

Whenever a function is called, we skip up to that function call's definition and execute THAT code before returning to our original call...If something is wrong in any of the functions that are utilized in your original function, it will throw everything off!


let findSum = (x: number, y: number, z: number): number => {
     return x + y - z;

let find average = (a: number, b: number, c: number): number => {
     let sumOfAll: number = findSum(a, b, c);
     let answer: number = sumOfAll / 3;
     return answer;

print(average(10, 15, 20));
//wheres the error?

When we call average(10,15,20), the wrong value will be printed...why?

Although the average function is correct, we see that the findSum function is incorrect...since it is called within the average function, the calculation will be incorrect! Use this logic in your own work!

I know something is wrong...but where?

We have used 'print' statements to display our final answers...but we can use them elsewhere too!

Every time the value you are calculating changes, try printing that current value. Is what is being printed what is expected? Using this debugging technique, you can pinpoint the exact line that something goes wrong!


let calculateSlope = (x1: number, x2: number, y1: number, y2: number): number => {
     let yTotal: number = y2 - y1;

     let xTotal: number = x2 - x1;

     let slope: number = yTotal / xTotal;

     return slope;
//notice that after every step, we print the value that was changed
//this way, we can find THE EXACT LINE that has an error