If/Else and Boolean Logic for JavaScript


#1

<PLEASE USE THIS TEMPLATE TO HELP YOU CREATE A GREAT POST!>

<Below this line, add a link to the EXACT exercise that you are stuck at.>
https://www.codecademy.com/courses/learn-javascript-functions/lessons/functions/exercises/function-expressions?action=lesson_resume&course_redirect=introduction-to-javascript

<Below this line, in what way does your code behave incorrectly? Include ALL error messages.>
Rather than using an if/else statement in the “isGreaterThan” function, I’ve been simply returning the evaluation of the logical function. However, the exercise returns an error message asking: “Did you change function isGreaterThan(numberOne, numberTwo) {} to const isGreaterThan = (numberOne, numberTwo) => {}?” Is there a difference between the two? The first example below returned positive results in the previous exercises, so I’m not sure whether this is a limitation of the exercise, or whether there’s a difference between function expressions and function declarations.

This is the code I originally had entered (which returned the error message):

const isGreaterThan = (numberOne, numberTwo) => {
  return (numberOne > numberTwo);
}

console.log(isGreaterThan(2,3));

and this is what I had to change it to (which returned no error):

const isGreaterThan = (numberOne, numberTwo) => {
  if (numberOne > numberTwo) {
    return true;
  } else {
    return false;
  }
}

console.log(isGreaterThan(2,3));

#2

well, the code you need to enter needs to be validated. This can be done several ways, you could call the function several times and see if the correct Boolean value is returned. the exercise could also check for presence of certain keywords like true, false, if and else

depending on how the validation is setup, which shortcuts will or will not work. Guess which one appeared to be used in this exercise


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.