BMI rate calculate
You are currently viewing a revision titled "BMI rate calculate", saved on 2024年10月11日 8:45 PM by pooja | |
---|---|
タイトル | BMI rate calculate |
コンテンツ | <!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BMI Calculator</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
input {
margin: 5px 0;
}
</style>
</head>
<body>
<h1>BMI Calculator</h1>
<label for="weight">Weight (kg):</label>
<input type="number" id="weight" required>
<br>
<label for="height">Height (m):</label>
<input type="number" step="0.01" id="height" required>
<br>
<button onclick="calculateBMI()">Calculate BMI</button>
<h2 id="result"></h2>
<script>
function calculateBMI() {
const weight = parseFloat(document.getElementById('weight').value);
const height = parseFloat(document.getElementById('height').value);
if (weight > 0 && height > 0) {
const bmi = weight / (height * height);
document.getElementById('result').innerText = `Your BMI is: ${bmi.toFixed(2)}`;
} else {
document.getElementById('result').innerText = 'Please enter valid values.';
}
}
</script>
</body>
</html>
...................................................................................................................................................
#!/usr/bin/perl
use strict;
use warnings;
use CGI qw(:standard);
print header;
print start_html("BMI Calculator");
if (param()) {
my $weight = param('weight');
my $height = param('height');
if ($height > 0) {
my $bmi = $weight / ($height ** 2);
print "<h2>Your BMI is: " . sprintf("%.2f", $bmi) . "</h2>";
} else {
print "<h2>Please enter a valid height.</h2>";
}
} else {
print start_form(-method => 'POST');
print "Weight (kg): ", textfield('weight'), br;
print "Height (m): ", textfield('height'), br;
print submit('Calculate');
print end_form;
}
print end_html; |
抜粋 | |
脚注 |