Ma ktoś może pojęcie dlaczego po wykonanych wyliczeniach zamiast wyniku pojawia się wszędzie NaN zamiast wyniku?
<?php
session_start();
if (!isset($_SESSION['zalogowany']))
{
header('Location: index.php');
exit();
}
require_once "connection.php";
$polaczenie = new mysqli($host, $db_user, $db_password, $db_name);
if ($polaczenie->connect_errno)
{
throw new Exception(mysqli_connect_errno());
}
$sql = "SELECT gender FROM uzytkownicy WHERE id='".$_SESSION['zalogowany_id']."'";
if ($rezultat = $polaczenie->query($sql))
{
$wynik = $rezultat->fetch_assoc();
$plec = $wynik['gender'];
}
?>
<!DOCTYPE html>
<html lang="pl">
<head>
<?php include('templates/head.php'); ?>
<script>
function calc() {
let A = document.getElementById("age").value;
let W = document.getElementById("weight").value;
let H = document.getElementById("height").value;
let S, R, activity;
let P = "<?php echo $plec; ?>";
if (document.getElementById("age").value.length == 0) {
document.getElementById("ATT").style = "color: red;"
document.getElementById("WTT").style = "display: none;"
document.getElementById("HTT").style = "display: none;"
return
}
if (document.getElementById("weight").value.length == 0) {
document.getElementById("ATT").style = "display: none;"
document.getElementById("HTT").style = "display: none;"
document.getElementById("WTT").style = "color: red;"
return
}
if (document.getElementById("height").value.length == 0) {
document.getElementById("ATT").style = "display: none;"
document.getElementById("WTT").style = "display: none;"
document.getElementById("HTT").style = "color: red;"
return
}
if (document.getElementById("male")) {
S = Math.round((9.99*W)+(6.25*H)-(4.92*A)+5)
//P = "mężczyzna"
}
else if (document.getElementById("female")) {
S = Math.round((9.99*W)+(6.25*H)-(4.92*A)-161)
//P = "kobieta"
}
if (document.getElementById("0").selected) {
R = S
}
if (document.getElementById("1").selected) {
R = S*1.2
activity = "1. Niewielka/Brak treningów"
}
if (document.getElementById("2").selected) {
R = S*1.35
activity = "2. Niska aktywność (treningi 1-3 razy/tydzień)"
}
if (document.getElementById("3").selected) {
R = S*1.55
activity = "3. Średnia aktywność (codzienna aktywność lub intensywne treningi 3-4 razy/tydzień)"
}
if (document.getElementById("4").selected) {
R = S*1.75
activity = "4. Wysoka aktywność (intensywne treningi 6-7 razy/tydzień)"
}
if (document.getElementById("5").selected) {
R = S*1.95
activity = "5. Bardzo wysoka aktywność (codzienne bardzo intensywne treningi lub praca fizyczna)"
}
document.getElementById("ATT").style = "display: none;"
document.getElementById("HTT").style = "display: none;"
document.getElementById("WTT").style = "display: none;"
document.getElementById("age").placeholder = " "
document.getElementById("weight").placeholder = "Kg"
document.getElementById("height").placeholder = "Cm"
document.getElementById("a").innerHTML = Math.round(R)
document.getElementById("b").innerHTML = Math.round(R*0.80)
document.getElementById("c").innerHTML = Math.round(R*1.20)
document.getElementById("ak").innerHTML = Math.round(R)
document.getElementById("ak-2").innerHTML = Math.round(S)
document.getElementById("a-1k").innerHTML = Math.round((R*0.80)*0.25)
document.getElementById("a-1g").innerHTML = Math.round(((R*0.80)*0.25)/4)
document.getElementById("a-2k").innerHTML = Math.round((R*0.80)*0.50)
document.getElementById("a-2g").innerHTML = Math.round(((R*0.80)*0.50)/4)
document.getElementById("a-3k").innerHTML = Math.round((R*0.80)*0.25)
document.getElementById("a-3g").innerHTML = Math.round(((R*0.80)*0.25)/9)
document.getElementById("bk").innerHTML = Math.round(R)
document.getElementById("bk-2").innerHTML = Math.round(S)
document.getElementById("b-1k").innerHTML = Math.round((R*0.80)*0.25)
document.getElementById("b-1g").innerHTML = Math.round(((R*0.80)*0.25)/4)
document.getElementById("b-2k").innerHTML = Math.round((R*0.80)*0.50)
document.getElementById("b-2g").innerHTML = Math.round(((R*0.80)*0.50)/4)
document.getElementById("b-3k").innerHTML = Math.round((R*0.80)*0.25)
document.getElementById("b-3g").innerHTML = Math.round(((R*0.80)*0.25)/9)
document.getElementById("bs").innerHTML = Math.round(R-(R*0.80))
document.getElementById("ck").innerHTML = Math.round(R)
document.getElementById("ck-2").innerHTML = Math.round(S)
document.getElementById("c-1k").innerHTML = Math.round((R*1.20)*0.25)
document.getElementById("c-1g").innerHTML = Math.round(((R*1.20)*0.25)/4)
document.getElementById("c-2k").innerHTML = Math.round((R*1.20)*0.50)
document.getElementById("c-2g").innerHTML = Math.round(((R*1.20)*0.50)/4)
document.getElementById("c-3k").innerHTML = Math.round((R*1.20)*0.25)
document.getElementById("c-3g").innerHTML = Math.round(((R*1.20)*0.25)/9)
document.getElementById("cs").innerHTML = Math.round((R*1.20)-R)
document.getElementById("Final").style = " margin: auto; margin-top: 1em; border-radius: 20px; margin-bottom: 30px"
if (document.getElementById("more").selected) {
document.getElementById("less-text-1").style = "display: none;"
document.getElementById("less-text-2").style = "display: none;"
document.getElementById("constant-text-1").style = "display: none;"
document.getElementById("constant-text-2").style = "display: none;"
document.getElementById("more-text-1").style = "display: block;"
document.getElementById("more-text-2").style = "display: table-row;"
document.getElementById("more-text-1").scrollIntoView();
dataLayer.push({
'event': 'calc',
'cel': 'chce przytyć',
'waga': W,
'wiek': A,
'wzrost' : H,
'płeć' : P,
'aktywność' : activity
});
}
if (document.getElementById("less").selected) {
document.getElementById("more-text-1").style = "display: none;"
document.getElementById("more-text-2").style = "display: none;"
document.getElementById("constant-text-1").style = "display: none;"
document.getElementById("constant-text-2").style = "display: none;"
document.getElementById("less-text-1").style = "display: block;"
document.getElementById("less-text-2").style = "display: table-row;"
document.getElementById("less-text-1").scrollIntoView();
dataLayer.push({
'event': 'calc',
'cel': 'chce schudnąć',
'waga': W,
'wiek': A,
'wzrost' : H,
'płeć' : P,
'aktywność' : activity
});
}
if (document.getElementById("constant").selected) {
document.getElementById("more-text-1").style = "display: none;"
document.getElementById("more-text-2").style = "display: none;"
document.getElementById("less-text-1").style = "display: none;"
document.getElementById("less-text-2").style = "display: none;"
document.getElementById("constant-text-1").style = "display: block;"
document.getElementById("constant-text-2").style = "display: table-row;"
document.getElementById("constant-text-1").scrollIntoView();
dataLayer.push({
'event': 'calc',
'cel': 'utrzymanie wagi',
'waga': W,
'wiek': A,
'wzrost' : H,
'płeć' : P,
'aktywność' : activity
});
}
}
</script>
gender jest pobrany z bazy danych gdzie jest albo male albo female