-1

I have a variable that basically has 25% chance of being false and a 75% chance of being true. Is there a way I can log an error to the console if it's throwError is equal to false?

const throwError = Math.random() > 0.25;

if (throwError === true) {
  console.log("yay!");
} else {
  logError("something went wrong!"); // I expect it to be something like this
}

3 Answers3

3

There is the console.error(...) function.

Or you can even throw new Error(yourMsgHere)

Tudor Constantin
  • 26,330
  • 7
  • 49
  • 72
1

Yes it is possible to log and error to the console.

console.log("Error");

Each browser has a console you can access and view the output of the console log.

Ctrl Shift J - this is the shortcut on windows

Take a look at this

https://developers.google.com/web/tools/chrome-devtools/

Federico klez Culloca
  • 26,308
  • 17
  • 56
  • 95
0

You can use the console.error() to through the error


You can also use the console.exception() to through exception .

For more detail , Visit this LINK

Pushprajsinh Chudasama
  • 7,772
  • 4
  • 20
  • 43