I am going through Codecademy's Into to JS course and I stumbled on a problem. https://www.codecademy.com/courses/introduction-to-javascript/lessons/higher-order-functions/exercises/review for reference.
I can't understand why the function containing the ternary returns "undefined", while the function containing the "if-else" statement works.
const addTwo = num => {
return num + 2;
}
const checkConsistentOutput = (func, val) => {
const checkA = val + 2
const checkB = func(val)
if (checkA === checkB) {
return func(val)
} else {
return "inconsistent results"
}
}
console.log(checkConsistentOutput(addTwo, 5));
VS
const addTwo = num => {
return num + 2;
}
const checkConsistentOutput = (func, val) => {
const checkA = val + 2
const checkB = func(val)
checkA === checkB ? func(val) : "inconsistent results"
}
console.log(checkConsistentOutput(addTwo, 5));
What am I missing and how should I write the ternary statement in order to make it work?