freeCodeCamp Challenge Guide: Returning Boolean Values from Functions

freeCodeCamp Challenge Guide: Returning Boolean Values from Functions
0.0 0

#1

You may recall from Comparison with the Equality Operator that all comparison operators return a boolean true or false value.

A common anti-pattern is to use an if/else statement to do a comparison and then return true/false:

function isEqual(a,b) {
  if(a === b) {
    return true;
  } else {
    return false;
  }
}

Since === returns true or false, we can simply return the result of the comparison:

function isEqual(a,b) {
  return a === b;
}

#2

I really don’t understand this one! can someone help?


#3

Watch what you have in Instructions. - create function less then
function isLess(a, b) {
// Fix this code
return a < b;

}
this would work


#4

Further explanation:

The purpose of isLess() is to determine whether a value is less than b value.
So if a is less than b, the answer should be TRUE. If not, you should receive a FALSE response in the console.


#5

This worked for me.

function isLess(a, b) {
switch (true) {
case a < b:
answer = true;
break;
case a > b:
answer = false;
break;
}
return answer;
}


#6

it works for me.

function isLess(a, b) {
  // Fix this code
  return a*3 === b*2;
}

// Change these values to test
isLess(10, 15);

#7

why so long, just:

function isLess(a,b) {
return a < b;
}

working fine