I'm trying to get "Hi I am David , and the number is even" shown on the console, but every time I ran the code "even" is shown as a number

Viewed 32

first part sums two numbers, second part checks whether the sum of the numbers is odd or even and the final part prints out the message but in this case it prints out 8 instead of even

let sum = (a, b) => {
    return a + b};


let evaluate = (c) => {
    if (c % 2 == 0) {
        console.log("Even")
    } else {
        console.log("odd")
    }
    return c;
};


let Hello = (name, status) => {
    let message = `Hi I am  ${name} , and the number is ${status}`;
    return message;
};
console.log( Hello("David", evaluate(sum(5, 3))));
1 Answers

As Sergey mentions above, returning a console.log is not the same as returning a string. I've re-written your code to return a string and it should now behave as expected.

let sum = (a, b) => {
    return a + b};


let evaluate = (c) => {
    if (c % 2 == 0) {
        return "Even";
    }
    return "Odd";
};


let Hello = (name, status) => {
    let message = `Hi I am  ${name} , and the number is ${status}`;
    return message;
};
console.log( Hello("David", evaluate(sum(5, 3))));

Related