Console.log(?) - confused about how to use this again

I’m in the early part of the JavaScript lessons and want to see the test output on the bottom screen - mostly because it’s fun. What would I console.log(here) in order to see the output of a function?

Example:

// Setup
function testEqual(val) {
  if (val) { // Change this line
    return "Equal";
  }
  return "Not Equal";
}

testEqual(10);

I tried to do console.log(val) and console.log(testEqual) but neither would show ‘equal’ or ‘not equal’ on the bottom portion of the screen. I’m likely missing a key concept here, but any insight appreciated!

Carl

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

It depends on where you want the log statement to be. If you want to print val inside the function, then you would need to put console.log(val) inside your function before the if.

If you want to print the output of the testEqual function when it is called with a value, then you would need the log statement to be outside the function and you would need a complete function call such as console.log(testEqual(10)) or console.log(testEqual(42)).

  1. Thank you for the readability! I forgot how to do this.

  2. This makes so much sense, like, “log the function with a value of x”. Or, as you pointed out, putting it in the function itself will make it automatically show the value.

Thank you again!

I’m glad I could help. Happy coding!