help with functions | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

help with functions

im having a little trouble with functions and was wondering if someone could help me:i dont really understand how getting multiple outputs out of a function.can i just seperate them with a comma or put two functions in one?i also dont understand how i would go about storing two outputs either.

22nd Nov 2016, 1:47 PM
Ángel Perales
Ángel Perales - avatar
1 Answer
+ 1
It is not possible to return multiple values at once. The possible solution is to add the output in a array or something similar in the language you use. Then you can assign the output to a variable. Example: function output() { //defining two variables var x = 0; var y = 1; //increase the variable number by 1 x++; y++; //The array which will be returned var z = []; //assigning value to 0 and 1 indexes. z[0] = x; z[1] = y; //returning the array as result return z; } //this variable will hold the result which is z {1,2}; var myvar = output();
22nd Nov 2016, 2:05 PM
L Bozhilov
L Bozhilov - avatar