Question: Index.php:

Index.php:
//set default values to be used when page first loads $scores = array(); $scores[0] = 70; $scores[1] = 80; $scores[2] = 90; $scores_string = ''; $score_total = 0; $score_average = 0; $max_rolls = 0; $average_rolls = 0;
//take action based on variable in POST array $action = filter_input(INPUT_POST, 'action'); switch ($action) { case 'process_scores': $scores = $_POST['scores'];
// validate the scores // TODO:(#6) Convert this if statement to a for loop if (empty($scores[0]) || empty($scores[1]) || empty($scores[2]) || !is_numeric($scores[0]) || !is_numeric($scores[1]) || !is_numeric($scores[2])) { $scores_string = 'You must enter three valid numbers for scores.'; break; }
// process the scores // TODO: (#5) Add code that calculates the score total -- DONE $scores_string = ''; foreach ($scores as $s) { $scores_string .= $s . '|'; } $scores_string = substr($scores_string, 0, strlen($scores_string)-1); for($i = 0; $i
break; case 'process_rolls': $number_to_roll = filter_input(INPUT_POST, 'number_to_roll', FILTER_VALIDATE_INT);
$total = 0; $count = 0; $max_rolls = -INF;
// TODO: (#8) convert this while loop to a for loop while ($count
break; } include 'loop_tester.php'; ?>
loop_tester.php:
Loop Tester
Process Scores
Process 1000 Die Rolls
main.css:
body { font-family: Arial, Helvetica, sans-serif; } main { width: 450px; margin: 0 auto; padding: 1em; background: white; border: 2px solid navy; } h1 { margin-top: 0; color: navy; } label { display: block; width: 8em; text-align: right; margin: 0 0 .5em; padding: 0 1em; float: left; } input, select { display: block; float: left; margin-bottom: .5em; margin-top: 0; } br { clear: left; }
Implement the score processing 5. In the index.php file, add code that calculates the score total. When you're done, clicking the Process Scores button should display the correct total and average. 6. In the index.php file, use a for loop to validate the user entries instead of using multiple conditions in a hard-coded if statement. 7. Test your changes to make sure they work correctly. Modify the roll processing 8. In the index.php file, modify the code that processes the rolls so it uses a for loop as the outer loop instead of a while loop 9. In the loop tester.php file, use a for loop to display the "
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
