자동 계산기 코드가 작동이 안됩니다.

안녕하세요, 저는 코딩과 관련해서는 완전히 문외한입니다.
논문에서 첨부된 의료와 관련된 자동 계산기 코드를 사용하고자 하는데,
무엇이 빠졌는지 작동이 전혀 되지 않습니다.
혹시 아래 코드에서 무엇이 빠졌는지 봐주실 수 있는 능력자분 계실까요.
감사합니다.

<style>
span.dropt {border-bottom: thin dotted; background: #ffeedd;}
span.dropt:hover {text-decoration: none; background: white; z-index: 10; }
span.dropt span {position: absolute; left: -9999px;
 margin: 20px 0 0 0px; padding: 8px 8px 8px 8px;
 border-style:solid; border-color:black; border-width:1px; z-index: 6;}
span.dropt:hover span {left: 2%; background: #FFEBD4;}
</style>
<html>
<body>
<h1><font face="arial"> Prediction model for 15-day unplanned readmission risk
</font></h1>
<p> <i> Usage: Fill in the form below. The predicted 15-day unplanned readmission risk will
be shown automatically once all fields are filled in.</i></p>
<table style="border-collapse: collapse">
<tr>
<td width=260><font face="arial">Age</font> </td>
<td><input type="text" id="Age" name="Age"
onchange="isValidAge(true)"></td>
<td id="numAge" width=700></td>
</tr>
<tr>
<td>
<font face="arial"size="3">Number of discharge medications</font>

</td>
<td><input type="text" id="numMeds" name="numMeds"
onchange="isValidNumMeds(true)"></td>
<td id="numMedsText" width=700></td>
</tr>
<tr>
<td><font face="arial"size="3">Prior diagnosis of anemia?</font> </td>
<td>
<select id="anemia" name="anemia" onchange="calculate()">
<option value="0" selected="selected">No</option>
<option value="1">Yes</option>
</select>
</td>
<td width=500></td>
</tr>
<tr>
<td><font face="arial"size="3">Prior diagnosis of COPD?</font></td>
<td>
<select id="copd" name="copd" onchange="calculate()">
<option value="0" selected="selected">No</option>
<option value="1">Yes</option>
</select>
</td>
<td width=500></td>
</tr>
<tr>
<td><font face="arial"size="3">Prior diagnosis of peptic ulcer
disease?</font></td>
<td>
<select id="pud" name="pud" onchange="calculate()">
<option value="0" selected="selected">No</option>
<option value="1">Yes</option>
</select>
</td>
<td width=500></td>
</tr>
<tr>
<td><font face="arial"size="3">Prior diagnosis of malignancy?</font></td>
<td>
<select id="malignancy" name="malignancy"
onchange="calculate()">
<option value="0" selected="selected">No</option>
<option value="1">Yes</option>
</select>
</td>
<td width=500></td>
</tr>
<tr>
<td width=260><font face="arial"size="3">Discharging against medical
advice?</font></td>
<td>
<select id="medAdvice" name="medAdvice"
onchange="checkMedAdvice()">
<option value="0" selected="selected">No</option>
<option value="1">Yes</option>
</select>
</td>
<td width=500></td>
</tr>
<tr id="discharge_tr">
<td><font face="arial"size="3">Discharge destination</font> </td>
<td>
<select id="discharge" name="discharge" onchange="calculate()">
<option value="1" selected="selected">Home</option>
<option value="2">Nursing home</option>
<option value="3">Community hospital</option>
<option value="4">Other acute care hospital</option>
</select>
</td>
<td width=500></td>
</tr>
</table>
<p id="output">&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p> <font face="verdana" size="2"> Developed by Dorajoo SR, See V, Chan CT, Tan ZYJ, Tan
DSY, Maryam S, Ong TT, Koomanan N, Yap CW & Chan A <br /> 20 May 2016 </font></p>
<body style="background-color: white">
</body>
<script>
function isNumber(n)
{
 return !isNaN(parseFloat(n)) && isFinite(n);
}
function checkMedAdvice()
{
var medAdvice = parseInt(document.getElementById("medAdvice").value);
if (medAdvice==1) document.getElementById("discharge_tr").style.display = "none";
else document.getElementById("discharge_tr").style.display = "";
calculate();
}
function isValidNumMeds(printError)
{
var varID = "numMeds"
var varMin = 1
var varMax = 28
var varErrorID = "numMedsText"
printError = printError || false
var x = document.getElementById(varID).value;
if (printError==true)
{
document.getElementById(varErrorID).innerHTML = "";
document.getElementById("output").innerHTML = "";
}
if (x=="") return false;
else if (!isNumber(x) | parseInt(x)!=x | x<0)
{
if (printError==true) document.getElementById(varErrorID).innerHTML = "Please
enter a valid number of medications";
return false;
}
else if (x<varMin | x>varMax)
{
if (printError==true) document.getElementById(varErrorID).innerHTML = "Number
of medications is out of limits seen during development of model (1 to 28 medications)";
}
if (printError==true) calculate()
else return true;
}
function calculate()
{
if (isValidNumMeds())
{
var Age = parseInt(document.getElementById("Age").value);
var numMeds = parseInt(document.getElementById("numMeds").value);
var malignancy = parseInt(document.getElementById("malignancy").value);
var pud = parseInt(document.getElementById("pud").value);
var anemia = parseInt(document.getElementById("anemia").value);
var copd = parseInt(document.getElementById("copd").value);
var medAdvice = parseInt(document.getElementById("medAdvice").value);
var discharge = parseInt(document.getElementById("discharge").value);
var coefSum = 0;
coefSum = 0.0184318 * Age +
 0.059871 * numMeds +
 1.21543 * malignancy +
 1.113508 * pud +
 0.7331728 * anemia +
 1.149663 * copd +
 -2.332857 ;
if (medAdvice==1) coefSum += 1.61846;
else
{
if (discharge==2) coefSum += 1.272528; // Nursing home
if (discharge==3) coefSum += -0.2432239 ; // Community hospital
else if (discharge==4) coefSum += -0.2432239; // Other acute
hospital
}
var y = 1.0 / (1.0 + Math.exp(-coefSum))
if (y > 0.5)
{
document.getElementById("output").innerHTML = "Patient is likely to be
readmitted within 15 days (Predicted probability of readmission: " +
(parseFloat(y).toFixed(2))*(100)+ "%)";
}
else
{
document.getElementById("output").innerHTML = "Patient is not likely to be
readmitted within 15 days (Predicted probability of readmission: " +
((parseFloat(y).toFixed(2))*100)+ "%)";
}
}
</script>

참고 바랍니다.

:thinking::thinking:

  1. 확인할 코드가 없습니다.
  2. 어디가 어떻게 작동하지 않는다는지 알 수가 없습니다. (에러코드, 증상 등)
  3. 논문과 관련된 질문일 경우 어떤 논문인지 제대로 인용처리 해주시기 바랍니다.

제가 추측하기엔 코드가 HTML이고 그래서 자연스레 렌더가 되어버린 것 같은데요…ㅋㅋㅋㅋ
그 바로 위에 CSS 코드도 있는 걸로 봐서는 그쪽이 맞는 것 같습니다.

관리자 권한을 사용해 코드를 인용처리 하였습니다. 질문자분께서는 이 점 숙지 바라며, 다음에 글을 올리실 때는 ``` 를 사용해 코드가 있는 단락을 묶어 인용처리 해주시기 바랍니다.

질문자님의 코드가 동작하지 않던 이유는 단순한 들여쓰기 ( indent ) 문제였습니다. 코드가 동작 할 수 있도록 뭔가 더 넣어야 할 부분은 없습니다.

아래 코드를 그대로 사용하시면 제대로 동작할 것입니다.

<style>
span.dropt {border-bottom: thin dotted; background: #ffeedd;}
span.dropt:hover {text-decoration: none; background: white; z-index: 10; }
span.dropt span {position: absolute; left: -9999px;
 margin: 20px 0 0 0px; padding: 8px 8px 8px 8px;
 border-style:solid; border-color:black; border-width:1px; z-index: 6;}
span.dropt:hover span {left: 2%; background: #FFEBD4;}
</style>
<html>
<body>
<h1><font face="arial"> Prediction model for 15-day unplanned readmission risk
</font></h1>
<p> <i> Usage: Fill in the form below. The predicted 15-day unplanned readmission risk will
be shown automatically once all fields are filled in.</i></p>
<table style="border-collapse: collapse">
<tr>
<td width=260><font face="arial">Age</font> </td>
<td><input type="text" id="Age" name="Age"
onchange="isValidAge(true)"></td>
<td id="numAge" width=700></td>
</tr>
<tr>
<td>
<font face="arial"size="3">Number of discharge medications</font>

</td>
<td><input type="text" id="numMeds" name="numMeds"
onchange="isValidNumMeds(true)"></td>
<td id="numMedsText" width=700></td>
</tr>
<tr>
<td><font face="arial"size="3">Prior diagnosis of anemia?</font> </td>
<td>
<select id="anemia" name="anemia" onchange="calculate()">
<option value="0" selected="selected">No</option>
<option value="1">Yes</option>
</select>
</td>
<td width=500></td>
</tr>
<tr>
<td><font face="arial"size="3">Prior diagnosis of COPD?</font></td>
<td>
<select id="copd" name="copd" onchange="calculate()">
<option value="0" selected="selected">No</option>
<option value="1">Yes</option>
</select>
</td>
<td width=500></td>
</tr>
<tr>
<td><font face="arial"size="3">Prior diagnosis of peptic ulcer
disease?</font></td>
<td>
<select id="pud" name="pud" onchange="calculate()">
<option value="0" selected="selected">No</option>
<option value="1">Yes</option>
</select>
</td>
<td width=500></td>
</tr>
<tr>
<td><font face="arial"size="3">Prior diagnosis of malignancy?</font></td>
<td>
<select id="malignancy" name="malignancy"
onchange="calculate()">
<option value="0" selected="selected">No</option>
<option value="1">Yes</option>
</select>
</td>
<td width=500></td>
</tr>
<tr>
<td width=260><font face="arial"size="3">Discharging against medical
advice?</font></td>
<td>
<select id="medAdvice" name="medAdvice"
onchange="checkMedAdvice()">
<option value="0" selected="selected">No</option>
<option value="1">Yes</option>
</select>
</td>
<td width=500></td>
</tr>
<tr id="discharge_tr">
<td><font face="arial"size="3">Discharge destination</font> </td>
<td>
<select id="discharge" name="discharge" onchange="calculate()">
<option value="1" selected="selected">Home</option>
<option value="2">Nursing home</option>
<option value="3">Community hospital</option>
<option value="4">Other acute care hospital</option>
</select>
</td>
<td width=500></td>
</tr>
</table>
<p id="output">&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p> <font face="verdana" size="2"> Developed by Dorajoo SR, See V, Chan CT, Tan ZYJ, Tan
DSY, Maryam S, Ong TT, Koomanan N, Yap CW & Chan A <br /> 20 May 2016 </font></p>
<body style="background-color: white">
</body>
<script>

function isNumber(n)
{
    return !isNaN(parseFloat(n)) && isFinite(n);
}
function checkMedAdvice()
{
    var medAdvice = parseInt(document.getElementById("medAdvice").value);
    if (medAdvice==1) document.getElementById("discharge_tr").style.display = "none";
    else document.getElementById("discharge_tr").style.display = "";
    calculate();
}

function isValidNumMeds(printError)
{
    var varID = "numMeds"
    var varMin = 1
    var varMax = 28
    var varErrorID = "numMedsText"
    printError = printError || false
    var x = document.getElementById(varID).value;
    
    if (printError==true)
    {
        document.getElementById(varErrorID).innerHTML = "";
        document.getElementById("output").innerHTML = "";
    }

    if (x=="") return false;
    else if (!isNumber(x) | parseInt(x)!=x | x<0)
    {
        if (printError==true) document.getElementById(varErrorID).innerHTML = "Please enter a valid number of medications";
        return false;
    }
    else if (x<varMin | x>varMax)
    {
        if (printError==true) document.getElementById(varErrorID).innerHTML = "Number of medications is out of limits seen during development of model (1 to 28 medications)";
    }
    
    if (printError==true) calculate()
    else return true;
}

function calculate()
{
    if (isValidNumMeds())
    {
        var Age = parseInt(document.getElementById("Age").value);
        var numMeds = parseInt(document.getElementById("numMeds").value);
        var malignancy = parseInt(document.getElementById("malignancy").value);
        var pud = parseInt(document.getElementById("pud").value);
        var anemia = parseInt(document.getElementById("anemia").value);
        var copd = parseInt(document.getElementById("copd").value);
        var medAdvice = parseInt(document.getElementById("medAdvice").value);
        var discharge = parseInt(document.getElementById("discharge").value);
        var coefSum = 0;
        coefSum = 0.0184318 * Age +
        0.059871 * numMeds +
        1.21543 * malignancy +
        1.113508 * pud +
        0.7331728 * anemia +
        1.149663 * copd +
        -2.332857 ;
        if (medAdvice==1) coefSum += 1.61846;
        else
        {
            if (discharge==2) coefSum += 1.272528; // Nursing home
            if (discharge==3) coefSum += -0.2432239 ; // Community hospital
            else if (discharge==4) coefSum += -0.2432239; // Other acute
        }
        
        var y = 1.0 / (1.0 + Math.exp(-coefSum))
        
        if (y > 0.5)
        {
            document.getElementById("output").innerHTML = "Patient is likely to be readmitted within 15 days (Predicted probability of readmission: " +
            (parseFloat(y).toFixed(2))*(100)+ "%)";
        }
        else
        {
            document.getElementById("output").innerHTML = "Patient is not likely to be readmitted within 15 days (Predicted probability of readmission: " +
            ((parseFloat(y).toFixed(2))*100)+ "%)";
        }
    }
}
</script>

ㅎㄷㄷㄷ 멋지네요.

파이슨도 아닌데 인덴트가 문제를…?

작성자 분이 올리신 기존 코드를 보시면

if (printError==true) document.getElementById(varErrorID).innerHTML = "Please
enter a valid number of medications";
return false;

이런 부분들이 있습니다. quote 때문에 코드가 실행되지 않는 문제가 발생하는 것이었기 때문에 인덴트 라는 단어를 사용한 것인데, 오해의 소지가 있었네요. 다음에 이런 답변을 쓸 때는 용어 선택에 조금 더 주의를 기울이도록 하겠습니다.

지적 감사합니다.