Write to Debug Console to See Variable Values?

Some of my advanced students would like to see the value of variables (which are seemingly not getting correct values). Is there a way to use the debug console to do this?

There are several ways to do this, that are easier to show than describe. Also because the toolbox is limited in Unit 3, you’ll probably need to do some amount of writing code in text mode…but…

because the variables in unit 3 are mostly function parameters (and therefore not global variables) the thing to do would be to insert console.log statements inside the function where you want to investigate the value. For example

function myFunc(size, numTimes){
      console.log(size);
      console.log(numTimes);
  
      // sometimes it helps to include a text message
     console.log("in myFunc, size is: " + size);
}

That’s the quick and dirty. If you can send a link to a project that’s having problems, I can show this and other methods for debugging it.

Baker
CSP Team

2 Likes

Perfect, works exactly as needed. Thanks!