Easy function that works in JS without ES6:
var evenOrOdd = function(n){
if(n % 2 == 1){
return "Odd";
} else {
return "Even";
}
}
console.log(evenOrOdd(3)); //returns odd
My attempt at restructuring this using ES6:
const evenOrOdd = (n) => {(n % 2 == 1) ? "Odd" : "Even"};
console.log(evenOrOdd(3)); //returns undefined
I'm following these examples here: 2ality and stoimen.
Why is this arrow function returning undefined
?