Basic JavaScript - Returning Boolean Values from Functions

Tell us what’s happening:

Following following example, I am unable to understand the prupose besdies 1 line of code instead of 4-5, the returnvalue is the same,

Your code so far

function isLess(a, b) {
  // Only change code below this line
  // if (a < b) {
  //   console.log(true)
  //   return true;
  // } else {
  //   console.log(false)
  //   return false;
  // }
  console.log( a < b)
  return  a < b;
  // Only change code above this line
}

isLess(10, 15);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36

Challenge Information:

Basic JavaScript - Returning Boolean Values from Functions

Welcome to the forum

Does the step ask to console.log or return?
Happy coding

Share Challenge Web Address.

I did console.log for my benefit, to see what is outputting, so from what I understand it is outputting same but how many code lines r written is the difference?

The test is checking for specific code, if there is anything extra the test may not pass.

I didn’t understand, what was purpose of the exercise coz it is like refactoring, 5 lines of code into 1, result is same. trying to find what is it teaching

Hi @mahassan

The exercise was showing how to simplify a function.

Having an understanding of code, writing , commenting, and simplifying it is generally what scripting is about.

My impression of the exercise was that there are many ways to write code, and having simple and elegant code is:

  1. quicker to write
  2. easier to read
  3. faster to debug
  4. processes faster
  5. requires less storage space

If you still have any lingering questions please feel free to start a new topic.

1 Like

that was my impression too but thought I might be missing something else too.