I have looked online about changing variables in an function but still doesn't work.
I'm trying to change the global variable in a function. An object with numbers are multiplied by each other. The function will be use several time with different global variables. so don't want to use there names directly.
HERE IS THE CODE
var homeTeamOppw = {"last_gp": 0.2, "2nd_gp": 0.2, "3rd_gp": 0.8, "4th_gp": 0.4, "5th_gp": 0.8};
ans = 0;
function timesArrayitems(teamOpp, array){
var num = 1;
for(item in array){
num = num * array[item];
}
teamOpp = num;
}
timesArrayitems(ans, homeTeamOppW);
console.log(ans);
The ans come out as undefine. Can someone explain please and thanks