Click here to Skip to main content
15,918,193 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:

I'm writting a simple code which gets two numbers as an input and returns the summation of them as the output:


What I have tried:

function summation(num1, num2) {
let sum = num1 + num2;
return ("The result is: "+ sum);


The problem is that for whatever compiler I use, I don't get any output.

Could someone please help?

Updated 21-Jan-23 20:10pm
Dave Kreskowiak 21-Jan-23 21:14pm    
Javascript? Javascript doesn't have a compiler. It's an interpreted language, normally used in a browser.

Are you talking about Java, which is NOT the same as javascript?
OriginalGriff 22-Jan-23 2:11am    
No, it's JS - the function keyword is a giveaway.
Dave Kreskowiak 22-Jan-23 9:40am    
I should have caught that. I'm going to blame the drugs for that one. :)
OriginalGriff 22-Jan-23 9:49am    
Medicinal or recreational? :laugh:
Dave Kreskowiak 22-Jan-23 9:54am    
Sadly, the former. My own fault for sitting on my ass too much driving a keyboard and mouse all day.

1 solution

Returning a value from a function in javascript (or any other language) does not automatically display it anywhere - you have to take the result and cause it to appear someWhere. If that wasn't the case, functions would become pretty much unusable as every time you called one, it would display the result even if the user doesn't need to see it!

Start here: JavaScript Functions[^] which shows an example of how to display a return value.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900