Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

# Thread: Algorithm Formula with a phrase outputted

1. ## Algorithm Formula with a phrase outputted

I've found a simple script (at http://www.javascriptkit.com/script/...bodymass.shtml) that determines someone's BPI that I'm now trying to alter to fit my basketball workout program.

Let me know if I'm close. I've got the formula to compute the desired value, but now I'm trying to figure out how to get the corresponding phrase to appear and how to round the value to 4 decimal places or less.

Here's what I have. ALMOST DONE?????? ANY help is greatly appreciated.

Code:
```<html>
<head>
<title>Input tutorial</title>
<script language="javascript">
function addNumbers()
{
var val1 = parseInt(document.getElementById("value1").value);
var val2 = parseInt(document.getElementById("value2").value);
var val3 = parseInt(document.getElementById("value3").value);
var val4 = parseInt(document.getElementById("value4").value);
var ansD = document.getElementById("answer");
ansD.value = (100-(25-val1)*5)/4 + (100-6.66667*(23-val2))/4 + (100-7.51*(15-val3))/4 + (100-4*(32-(val4)))/4 ;
}

function checkform(form) {

if (value1==null||value1.length==0 || value2==null||value2.length==0 || value3==null||value3.length==0 || value4==null||value4.length==0){
alert("\nPlease complete the form first");
return false;
}

else if (parseFloat(value1) < 0||
parseFloat(value1) >=40||
parseFloat(value2) < 0||
parseFloat(value2) >=40)
parseFloat(value3) < 0||
parseFloat(value3) >=40||
parseFloat(value4) <= 0||
parseFloat(value4) >=31){
alert("\nDo you know what you're doing? \nPlease enter your scores again.");
ClearForm(form);
return false;
}
return true;

}

function computeform(form) {

if (answer >90) {
form.my_comment.value="Amazing Job!!";
}

else if (answer >80 && yourbmi <=90) {
form.my_comment.value="You're doing very well.";
}

else if (answer >65 && yourbmi <=80) {
form.my_comment.value="Keep up the great work";
}

else if (answer >50 && yourbmi <=65) {
form.my_comment.value="You need to push it a little harder";
}

else if (answer >=35 && yourbmi <=50) {
form.my_comment.value="You can do better than that!";
}

else if (answer >=20 && yourbmi <35) {
form.my_comment.value="Poor performance";
}

else if (answer >=10 && yourbmi <20) {
form.my_comment.value="You must try harder than that";
}

else if (answer <10) {
form.my_comment.value="You're definitely not giving it all your effort ";
}

}
return;
}
</SCRIPT>

</head>
<body>
XDrill = <input type="text" id="value1" name="value1" value="" SIZE=4 />
2ptrs = <input type="text" id="value2" name="value2" value="" SIZE=4/>
3ptrs = <input type="text" id="value3" name="value3" value="" SIZE=4/>
Nash = <input type="text" id="value4" name="value4" value="" SIZE=4/>
<input type="button" name="Sumbit" value="Click here" onclick="javascript<b></b>:addNumbers()"/>
<br><br>Score = <input type="text" id="answer" name="answer" value=""/ SIZE=4>
</body>
</html>```

• I'm making a bit more headway. I figured out that I probably need some sort of call function to actually make one of the options appear. Can anyone help with that?

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•