vendredi 3 décembre 2021

(PHP) having issues making a foreach loop that rolls a dice for 6 characters using rand() and compares their old stat with the new one from dice [closed]

I have been stuck on this PHP exercise for almost a week, the multiple values in the array are confusing me.

exercise: Here is the code representing a group of four characters in an associative array whose key is the name of the character.

$characters = [
  "Ganolon" => ["Strength" => 1, "Dexterity" => 2,
  "Intelligence" => 6, "Wisdom" => 6, "Charisma" => 5],
  "Cony" => ["Strength" => 5, "Dexterity" => 4,
  "Intelligence" => 3, "Wisdom" => 3, "Charisma" => 6],
  "Aegon" => ["Strength" => 6, "Dexterity" => 5,
  "Intelligence" => 5, "Wisdom" => 1, "Charisma" => 5],
  "Mountain" => ["Strength" => 1, "Dexterity" => 3,
  "Intelligence" => 4, "Wisdom" => 5, "Charisma" => 3]
];

From this array, write the code to do the following operations: a) Have all the characters take a Charisma test, by rolling a 6-sided dice for each character (use rand ()!)and compare the result with the character's initial Charisma attribute. If his attribute is greater than or equal to the result obtained on the dice, the character has passed the test. Generate a UL list showing each of the test results, including a message saying if the character has passed the test.

Heres what I have so far:

foreach ($characters as $x => $value) {
  $diceThrow = rand(1,6)

  if($diceThrow <= ) {}
}



Aucun commentaire:

Enregistrer un commentaire