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: Trying to make a arthmitic code, with interp of the math.

1. ## Trying to make a arthmitic code, with interp of the math.

I am trying to divide two numbers, display the value, then display what the value means. I am newbie, and trying to teach this to myself.

I have the division displaying in a input box with a name of "total".
I want to have the value from "total" display in an input box with a name of "interpretation".

Do I use "c" or "total" to call the value?

To write out "interpretation" do I use document.write, document.interpretation.write.?

Code:
```<!doctype html>
<script language="javascript" type="text/javascript">
function division(){
var a=Number(document.calculator.number1.value);
var b=Number(document.calculator.number2.value);
var c=a/b;
document.calculator.total.value=c;
}

}

function interpretABI() {
if (total >= 1) {
document.write.interpretation("normal");
}
else if ((total < 1) && (c >= 0.5)) {
interpretation = "lower extremity and arterial insufficiency";
}
else (total< 0.5) {
interpretation = "severe ischemia";
}
return interpretation;
}
}

function division2(){
division()
interpretABI()

}
</script>```

• 1. using functions just to call other function is kind of meaningless - if the code is to run sequentially, just put it all into one function
2. if you know the values from a text input are to be divided or multiplied there is no need to convert them to numbers - this will happen automatically
3. try to avoid document.write wherever possible (which is almost always) - it wipes out the rest of your page. you can use innerHTML for a div or set a text input's value just as easily
4. c is your variable, total is just the name of your text input. Simpler to work with variables.
5. you can use
Code:
```else {
interpretation = "severe ischemia";
}```
or
Code:
```else if (c< 0.5) {
interpretation = "severe ischemia";
}```
but
Code:
```else (c< 0.5) {
interpretation = "severe ischemia";
}```
is meaningless.

here's one way to do what you are trying to do...

Code:
```<body>
<form name="calculator">
<input type="text" name="number1"/>
<input type="text" name="number2"/>
<input type="button" value="calculate" onclick="division()"/>
<input type="text" name="total"/>
</form>
<div id="results"></div>
<script language="javascript" type="text/javascript">
function division(){
var a=document.calculator.number1.value;
var b=document.calculator.number2.value;
var c=a/b;
document.calculator.total.value=c;

if (c >= 1) {
interpretation="normal";
}
else if ((c < 1) && (c >= 0.5)) {
interpretation = "lower extremity and arterial insufficiency";
}
else if (c< 0.5) {
interpretation = "severe ischemia";
}
document.getElementById("results").innerHTML=interpretation;
}

</script>
</body>```

• Guys thanks a that helps me a lot, and its good to see different ways of doing things.

•

#### Posting Permissions

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