player health c# to JS convertion error

hey guys, i just converted a C# player health script to JS and i get an error "DivideByZeroException: Division by zero.

heres the code:

var MaxHealth = 100;
var CurHealth = 100;
function Update () {
}

function OnGUI () {
	GUI.Box(Rect(40,40,Screen.width /2 /(MaxHealth / CurHealth), 20), CurHealth + "/" + MaxHealth); 
	}

i cant understand why this is happening but i think its this part

Screen.width /2 -->/<--(MaxHealth / CurHealth)

could somone also explain this line of code to me? im having trouble understanding the math XD

from what i can make is

Screen.width "divided by" maxhealth "which is divided by" curHealth;

oh and i fixed the code:

var MaxHealth = 100;
var CurHealth = 100;

var Loc : Vector2 = Vector2 (100,100);
var Twoe = 400;
function Update () {
}

function OnGUI () {
	GUI.Box(Rect(40,40,Twoe /2 /(MaxHealth / CurHealth), 20), CurHealth + "/" + MaxHealth); 
	}

Instead of dividing by (maxhealth/curhealth), multiply by (curhealth/maxhealth).
When curhealth reaches zero, maxhealth/curhealth tries to perform a divide-by-zero operation.

The math is
Screen width
multiplied by
cur divided by max

Cur divided by max can “never” be more than one or less than zero, so you’ll get a percentage of screen width back. At cur=0, you’ll get 0; at cur=max, you’ll get 100% of screen width.

thanks alot man, really helps :smile:!