Put positive sign on positive number in innerHTML

Hello JavaScript Jedis!

I wonder if anyone can help me with a very simplepositivenumber.hype.zip (17.9 KB) issue I have with my function. It all works splendidly except I would really like it if the chargeboxoneone innerHTML would show a positive sign when the calculation of z yields a positive number. I have tried many snippets of code which either ruins my function or has no positive effect (pun intended).

If anyone fancies completing a quick fix on my function I have attached it.

Many thanks in advance to you wonderful people.

You can check the positivity of a number using ‘Math.sign’

So your script would be:

	var plusCharge = hypeDocument.currentTimeInTimelineNamed('unipos');
	
		
	var minusCharge = hypeDocument.currentTimeInTimelineNamed('unineg');
	
	var x = minusCharge * 30;
	
	var y = plusCharge * 30;
	
	var z = y - x;
	
	zSign = "";
	if (Math.sign(z) == 1) { 	
		zSign = "+";
	}
		
	hypeDocument.getElementById('chargeboxoneone').innerHTML = zSign + (z).toFixed(0);
1 Like

Wonderful Daniel. Thank you.

1 Like