I am trying to return multiple values from different functions. The starting point is a bidimensional array. An example of the code is:
var items = [[0,1],[1,2],[0,2]];
var a;
var b;
function first() {
a = items[Math.floor(Math.random() * items.length)];
return a;
}
function second() {
b = a[Math.floor(Math.random() * 2)];
return b;
}
function third (){
first();
second();
}
third();
If I write the code outside the functions, everything works fine. When I use functions and replace return with console.log, it works. If I use functions and return (as in the code reported above), it gives me undefined. I didn't find solutions. Why the code isn't working?
Thanks in advance
third()to do ?aandbare both defined after you executethird().thirdto return something, then you need write areturnstatement inthird.var third = _ => [first(),second()];could be a start.