We're close to being done with our random Pokemon generator! Let's do a few changes to the contract to create a random Pokemon.
-
The maximum HP of any Pokemon should be less than 1000. Define a define constant named
HP_LIMIT
equal to 1000. -
Remove the
_dna
and_HP
arguments from the_createPokemon
function declaration. -
Inside
_createPokemon
, create auint256
variablerandomDNA
. Call the function_generateRandomDNA
using theself
environment variable and pass the_name
argument. Set the result equal torandomDNA
. -
Inside
_createPokemon
, create auint256
variablerandomHP
. Set its value equal torandomDNA
modulus (%
)HP_LIMIT
. -
Inside
_createPokemon
, create a variablenewPokemon
ofPokemon
type. Use the_name
argument,randomDNA
,randomHP
to define thenewPokemon
. -
Inside
_createPokemon
, populatepokemonList
using the keytotalPokemonCount
and value asnewPokemon
. Remember to useself
environment variable to access the storage variables. -
Modify the
_createPokemon
function declaration so that it returns aPokemon
. -
At the end of the
_createPokemon
function, returnnewPokemon
.