Is it possible to call a Javascript Function in Sugarcube...
Yes, and the story format includes many of its own JavaScript functions that you can use.
...giving the Java Script Function three variables to work with?
It is unclear if by "variables" you mean: function arguments; or story variables; but either way you can pass as many arguments to a JavaScript function as it is setup to recieve, and even if you pass in more than that those values are accessible via the special arguments object.
Can a Javascript function return more then one value
No, a function can only return a single value. However that single value can be an instance of an 'collection' type object (like an Array, a Map, or a Generic Object), which in turn can contain multiple values.
Any JavaScript code you place within your project's Story Javascript area is executed within what's know as a Private Scope, the same is true for any JavaScript code you execute using the <<script>> macro, This means that any functions you define within those areas are unavailable to be used outside of those area, unless you manually change those functions scope from Private to 'Global' like.
There are a number of ways you raise the scope of such functions, two of them being:
1. Define the function on SugarCube's special setup object.
This object is available 'globally' from most places you would call JavaScript functions from, however you can't access it from the on<event-name> attibutes of a HTML element tag.
setup.hello = function (name) {
return "Hello ' + name + ', how are you?';
};
note: You need to include the setup object's name when you call such a function..
<<= setup.hello('Jane')>>
2. Define the function on the web-browser's special window object.
This object is available 'globally' anywhere you can execute JavaScript, including from the on<event-name> attibutes of a HTML element tag.
window.hello = function (name) {
return "Hello ' + name + ', how are you?';
};
note: You don't need to include the window object's name when you call such a function, but you can if you want to.
<<= hello('Jane')>>
<<= window.hello('John')>>
warning: Web-browser developers (and some third-party JavaScript library developers) also use this object to contain their function / property definitions, so some care needs to be taken when defining your own because you may be overwriting someone else's. This is why we generally recommend using the setup object instead, unless you need to use the function from an on<event-name> attibutes of a HTML element tag.