javascript - how to add and subtract on single click with two different values -


I am creating a game, now in the form of code, when I click on the attack, the power of the enemies randomly , But I want the player to be different, but the random value should be different from one of the enemies. If possible, then there can also be an alternative option for randomly increasing the players and reducing it. Because the enemy is still attacking

appearence (and Present):

Code:

   

& lt; Body onload = "start ()" & gt; & Lt; Input type = "button" name = "doit" id = "doit" value = "attack!" Onclick = "hitEnemy ();" & Gt; & Lt; Br / & lt; Span & gt; Athletics Health & lt; / Span & gt; & Lt; Div style = "font-ize: 3em;" Id = "playerhalf" & gt; & Lt; / Div & gt; & Lt; Period & gt; Enemyhealth's & lt; / Span & gt; & Lt; Div style = "font-size: 3em;" Id = "enemyhall" & gt; & Lt; / Div & gt; & Lt; Br / & gt; & Lt; Span & gt; You did: & lt; / Span & gt; & Lt; Span style = "font-size: 3em;" Id = "damage" & gt; & Lt; / Span & gt; & Lt; Period & gt; The & lt; / Span & gt; & Lt; / Body & gt;

This question looks like homework, have you written the code yet? If you have not done so, then try to read it and understand what each function is doing and where it is being brought from.


The random value must be different from one of the enemies

Question: How can I generate a random integer?

A: Here is a general use function to generate pseudo random integer

  function rand_int (maximum, minimum) {minutes = minutes | 0; If (max === (max | 0)) if (maximum  0  and (but not equal to)  1 .  x | 0  variable is used to convert to 32-bit integers. The filing point number is always changed to "Goal down" in the integer. This is  x | Works better than    

An alternate option may be to increase the players randomly

A: Second Type button is created due to the following:

  playerHealth + = rand_int (10); // Add between 0 and 10  

and also reduce it because the enemy is still attacking

Where do I say? Change the code for the enemy? Make a copy of

A: function hitEnemy , change it to hitPlayer and the enemy To player for example, call it after calling hitEnemy

  & lt; Input type = "button" name = "doit" id = "doit" value = "attack!" Onclick = "hitEnemy (); hitPlayer ();" / & Gt;  

Comments