Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript Basics (Retired) Introducing JavaScript The Console Challenge Answer

Mindaugas Kuliesius
Mindaugas Kuliesius
3,553 Points

what is the importance of using console.log start program and end program? if all is alright the point of using it?

Cause im lil bit confused with console.log which are used at the start and at the end is it just for pure showing that everything is inspected and working properly or it has some other meanings?

1 Answer

Cory Harkins
Cory Harkins
16,500 Points

console.log(); is extremely useful to help you find out where a program isn't executing, or to give you a status.

You don't HAVE to log your program, yet, if your function syntax is wrong or your statements are wrong and there are no log methods within, you could have a hard time figuring out WHY your function isn't working.

console.log("Booted up...");
var g = false;

function run(a,b) {
  console.log("Stage 1. Testing Condition if a is less than b");
  if (a < b) {
  g=true;
    if (g === true) {
        console.log("Stage 1 successful. This conditional statement is operational");
        return a;
    }
  } else if (a > b) {
     console.log("Stage 1 unsuccessful. " + a + " is greater than " + b ".");
     }
}

Just squeezed that example out, may have some syntax errors, shrug. The intent is to show how logging to the console can keep you updated on what is going on.