Question

These lines are the culprit: I was getting negative numbers so I decided to use the Math.max to ensure that the results would be no less than 0, but now I'm getting errors. My search just found me this method to use, but is there some particular Syntax I need in this form?

x.hp-=Math.max(0,(y.atk-x.def));
y.hp-=Math.max(0,(x.atk-y.def));

Everything works now, Thanks. The incorrect edit was due to a redundant ( opening parentheses.

Was it helpful?

Solution 3

Contrary to other answers here,

(Math.max(0,(y.atk-x.def))

has an extra parenthesis, at the beginning. Remove it:

Math.max(0,(y.atk-x.def))

You can indeed put an extra pair around the whole thing, as you have started to do, and as other answers appear to insist is necessary, but it isn't. It's redundant.

OTHER TIPS

) is missing in for Math.max method. i.e (Math.max(0,(y.atk-x.def)))

(Math.max(0,(x.atk-y.def)))
(Math.max(0,(y.atk-x.def)))

end both with " ) "

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top