javascript not working Jul 04, 2023 By Kevin McGrath 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
Jürgen Schoenemeyer 10 months ago07/04/23 at 4:43 pm (UTC) 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( ... )
Kevin McGrath Author Jürgen Schoenemeyer 10 months ago07/04/23 at 11:45 pm (UTC) 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!
2 Replies
"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( ... )
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!