I’m new to Javascript and been learning. I’m trying to set a button to activate random functions. button is fine and if I assign getGroupOne() to a button or getGroupTwo() to a button it works fine.
The only problem is somewhere in the following code.
Well when I click my button only getGroupTwo() works with the following code,
function getGroup() {
var Group = new Array (getGroupOne(), getGroupTwo());
var whichOne = Math.floor(Math.random()*Group.length);
return Group[whichOne];};
But when I flip them … only getGroupOne() works with the following code,
function getGroup() {
var Group = new Array (getGroupTwo(), getGroupOne());
var whichOne = Math.floor(Math.random()*Group.length);
return Group[whichOne];};
Could someone let me know what is the problem, I looked at a couple answers but not completly sure how to fix this.
Thank you,
If you want to return function references, you should write it like this: