PDA

Click to See Complete Forum and Search --> : Multiple If statements


messup000
Jan 11th, 2006, 08:44 PM
Hey everyone I need a little help again :( I am rewriting my calculator program and am having problems with my code...


function disp_prompt()
{
var i= document.getElementById("investment").value;
var r= document.getElementById("reinvest").value;
r=r - 0;
i=i - 0;
c=0+1
s=0
s1=100
s2=1000
s3=10000
q=100
q2=200
q3=300
total=0

if (i>s && i<s1);
if (c=1)<----- I cant get JS to recognize this code it just passes over it... or just doesnt do anything
{
total=i + i * q / 100
for (i=2;i<=r;i++)
total=total + total * q / 100

document.getElementById("profit").value= "$" +total 'but if i add a "+ c" it will add the number...

}
else
{
total=1000009

document.getElementById("profit").value= "$" +total
}
}




What am I doing wrong????

bulletrick
Jan 11th, 2006, 09:11 PM
if (i>s && i<s1);

What does this mean? Try using the Watch Window. It's very helpful. ;)

messup000
Jan 11th, 2006, 09:27 PM
if i>0 and if i<100

watch window? you mean like the vbcode window

messup000
Jan 11th, 2006, 09:41 PM
well i ended up using c<0 or c>0 instead... it seemed to work so thx for the help anyway...

Kevin1991
Dec 25th, 2006, 03:23 AM
if (i>s && i<s1);

Do not contain ";" behind if statement
Missing "{", so code is terminated!

visualAd
Dec 26th, 2006, 06:27 AM
Hey everyone I need a little help again :( I am rewriting my calculator program and am having problems with my code...


function disp_prompt()
{
var i= document.getElementById("investment").value;
var r= document.getElementById("reinvest").value;
r=r - 0;
i=i - 0;
c=0+1
s=0
s1=100
s2=1000
s3=10000
q=100
q2=200
q3=300
total=0

if (i>s && i<s1);
if (c=1)<----- I cant get JS to recognize this code it just passes over it... or just doesnt do anything
{
total=i + i * q / 100
for (i=2;i<=r;i++)
total=total + total * q / 100

document.getElementById("profit").value= "$" +total 'but if i add a "+ c" it will add the number...

}
else
{
total=1000009

document.getElementById("profit").value= "$" +total
}
}




What am I doing wrong????
c=1 <-- will assign the value of 1 to c and take the left most side of the expression after assignment as the vlaue (1). Hence it will always evaluate to true.

Instead of using the assignment operator =, you should use the equality operator ==

if (c == 1)