How do I call one of the listed functions based on the value of the variable called_function
?
function a() { alert('You called the a function.'); }
function b() { alert('You called the b function'); }
function c() { alert('You called the c function'); }
const possible_strings = ["a", "b", "c"];
const called_function = Math.floor(Math.random() * possible_strings.length);
This does not work:
window[called_function]();
When running window[called_function]();
, it says undefined.