Forum Discussion

KevinMcGrath's avatar
KevinMcGrath
Community Member
2 years ago

javascript not working

Hi, 

I'm running the following JavaScript but it doesn't work (variable stays at 0)

Can anyone tell me where I've gone wrong?

let player = GetPlayer();

let num1 = player.GetVar(“Total_Money”);
let num2 = player.GetVar(“COUNT_employees”);

let result = Math.(num1/num2); 

player.SetVar(“Ave”, result);

Many thanks

  •  

    let result = Math.(num1/num2); 

    "Math." is the problem  - it is only the first half of the function name

    if you want to round to an integer, the function is Math.round( ... )

    • KevinMcGrath's avatar
      KevinMcGrath
      Community Member

      Thanks so much! Got it working. It also wasn't recognising things with "..." so I swapped to '...' and swapped let to var and it's working correctly now. So happy. Thank you!