JavaScript JavaScript Basics 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
15,686 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) {
    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.