Skip to content
Advertisement

How can I make sure that I can print 0 instead a negative number to refer as the enemy being dead in a fighting game

I’m a fairly new programmer, but I am trying to make a fighting game code, but I have been stumped on one part, within my code I am trying to make sure that when the enemy health = 0, it will end. I can make the program end, well. But I don’t want to enemy health to go under 0, it can work with me fine, but I really want to change this.

JavaScript

so what happens when the program is ran, it will generate numbers and decreases x using those generated numbers. But when running the program, I want the code to only limit itself 0 health and not go under. Sorry if i horribly explained it simply put, I want a way so x will be capped at 0, and it will not print negative numbers and instead print some sample text like enemy died.

Advertisement

Answer

use max function like t his:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement