BMI calculation/241011
You are currently viewing a revision titled "BMI calculation/241011", saved on 2024年10月11日 8:53 PM by Suna | |
---|---|
タイトル | BMI calculation/241011 |
コンテンツ | BMI Calculatorfunction 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; |
抜粋 | |
脚注 |