please edit the code below to add a condition to your function . If the number of hours exceeds 40 hours then assign a 5% bonus to the wage, if it's between 30-40 assign 3% bonus to the wage. "> Number of Hours Worked: Hourly Wage:
please edit the code below to add a condition to your function . If the number of hours exceeds 40 hours then assign a 5% bonus to the wage, if it's between 30-40 assign 3% bonus to the wage.
<?php
function calculateWage($hours, $wage) {
$wage = $hours * $wage;
return $wage;
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$hours = $_POST['hours'];
$wage = $_POST['wage'];
// call the calculateWage function to get the wage
$wage = calculateWage($hours, $wage);
// print the result message
echo "Your wage is: $" . number_format($wage, 2);
// repopulate the form fields with the input values
$hours = isset($_POST['hours']) ? htmlspecialchars($_POST['hours']) : '';
$wage = isset($_POST['wage']) ? htmlspecialchars($_POST['wage']) : '';
} else {
// set default values for the form fields
$hours = '';
$wage = '';
}
?>
<form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>">
<label for="hours">Number of Hours Worked:</label>
<input type="text" name="hours" value="<?php echo $hours; ?>"><br><br>
<label for="wage">Hourly Wage:</label>
<input type="text" name="wage" value="<?php echo $wage; ?>"><br><br>
<input type="submit" value="Calculate">
</form>
Step by step
Solved in 2 steps