TestProject Forum

Javascript and return value in parameter [SOLVED]

Hello,

How do I save the return value of a javascript function into a parameter?
Currently, for some reason the result I am getting into the parameter is empty.

For example, let’s say that my function is the following:

myFunction();

function myFunction()
{
for(let i = 0; i < 10; i++)
{
if(i == 5)
{
return i;
}
}
}

In the OUTPUTS section I have a parameter called ‘result’ as an Output; however, if this is executed the parameter remains empty.

This parameter will be used in the following step as an input value.

One other thing I tried was having the parameter name as the assigned valued in the returned function:
{result} = myFunction();

But of course, this fails as it is not allowed.

Greatly appreciate your help!

All the best!

Hi @luis.stolk.
You need a return value in the end not inside a function, try this logic instead:

var x;
myFunction();

function myFunction()
{
for(let i = 0; i < 10; i++)
{
if(i == 5){
return x=i;
}
}
}
return x;