Today I made this! I am very proud and feel like my Javascript knowledge is coming together, thank you to all the people who’ve helped me on the forum.

This calculates the sum of three numbers, outputs the result then tells you if the number is negative, zero or positive.

Great job! The reason it’s giving you weird results is because your initial maths function isn’t returning anything. It is successfully logging the number you want to the console, but it is unable to pass this result to calculated because there is no return statement!

Also, the way your following code is written, “Your number is negative” will only be logged to the console is the value of calculated is equal to -1. I think maybe you meant to put

So looking at your Codepen as it is now (which I would recommend posting along with your replies), you have written return maths, which is not what you want to return. Because your function is designed to perform math operations on a group of numbers, the returned value should be the final value after those operations are performed!

So from there you have a few choices. As @colinthornton mentioned above, you could first save the math result to a variable, use that variable in your console.log, and then return that variable.

Or if you want to change as little as possible of your code as it is now, return one plus two plus three. However I would recommend the first option as it is cleaner and reduces repeated code!

I tried to do that but it won’t return a number anymore.

//Declare the function
function maths(one, two, three){
//change the sum and log in the console
let sum = one + two + three;
return sum;
}
//initialise the calculated variable. assign calculated to the function and call it with those arguments
let calculated = maths(1,2,2);
//if the number is negative log it as such
if (calculated <= -1){
console.log("Your number is negative");
}
//if the number is 0 log it as such
else if (calculated == 0){
console.log("Your number is 0");
}
//if the number is anything else it will be positive so log it as such
else{
console.log("Your number is positive");
}

Looks like you deleted the console.log from your maths function. From your above code, don’t change anything else, just put the console.log back in between your sum declaration and your return statement and it should work just as you want!

The function still doesn’t add the numbers together. My result is ‘122’, not the sum of adding those numbers.

//Declare the function
function maths(one, two, three){
//change the sum and log in the console
let sum = one + two + three;
console.log("Your number is " + one + two + three);
return sum;
}
//initialise the calculated variable. assign calculated to the function and call it with those arguments
let calculated = maths(1,2,2);
//if the number is negative log it as such
if (calculated <= -1){
console.log("Your number is negative");
}
//if the number is 0 log it as such
else if (calculated == 0){
console.log("Your number is 0");
}
//if the number is anything else it will be positive so log it as such
else{
console.log("Your number is positive");
}