Jesdisciple

07-25-2006, 08:10 PM

I was writing a code to calculate any three numbers with each of the four arithmetic signs (+,-,*,/) alternating positions in the two slots. A simplified version of the troublesome code is below. In both FF1 and IE6, it comes up with the number 11 for (x+x)/x and 21 for (10+5)/5, and FF1 then deletes the text. (I thought maybe it was just the IE6 parser, so I tried FF1. I'm assuming FF1 has a completely separate problem.) I find that if I feed the number directly into the JS -(5+5)/5-, it comes up with 2, the correct answer, but can't handle input variables. It's apparently calculating y/x and z/x and adding the quotients as strings, so (10+5)/5="2"+"1" and (5+5)/5="1"+"1".

<html>

<head>

<title>

Oddness...

</title>

<script type="text/javascript">

function calc(x,y,z){

var problemChild=y+z

var yzxaddidiv=problemChild/x

ABC=Math.round(yzxaddidiv)

if(yzxaddidiv!=ABC){

yzxaddidiv="N/A"

}

document.getElementById("output").value=yzxaddidiv

}

</script>

</head>

<body>

<form id="calc">

<input type=text id="x" />

<input type=text id="y" />

<input type=text id="z" />

<button onClick=calc(x.value,y.value,z.value)>Calculate</button>

</form>

<form id="result">

<textarea id="output" rows="10" cols="30"></textarea>

</form>

</body>

</html>Is this everyone's computer or just mine? Anyone know how to get around it?

<html>

<head>

<title>

Oddness...

</title>

<script type="text/javascript">

function calc(x,y,z){

var problemChild=y+z

var yzxaddidiv=problemChild/x

ABC=Math.round(yzxaddidiv)

if(yzxaddidiv!=ABC){

yzxaddidiv="N/A"

}

document.getElementById("output").value=yzxaddidiv

}

</script>

</head>

<body>

<form id="calc">

<input type=text id="x" />

<input type=text id="y" />

<input type=text id="z" />

<button onClick=calc(x.value,y.value,z.value)>Calculate</button>

</form>

<form id="result">

<textarea id="output" rows="10" cols="30"></textarea>

</form>

</body>

</html>Is this everyone's computer or just mine? Anyone know how to get around it?