BMI calculation/241011

BMI calculation/241011

BMI Calculator

body {
font-family: Arial, sans-serif;
margin: 20px;
}
input {
margin: 5px 0;
}

BMI Calculator

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.’;
}
}

…………………………………………………………………………….
#!/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 “

Your BMI is: ” . sprintf(“%.2f”, $bmi) . “

“;
} else {
print “

Please enter a valid height.

“;
}
} 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;

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です