...

View Full Version : Javascript Question/Problem



slvermoondragon
03-14-2009, 06:02 PM
Hi, I am new to Javascript and don't know that much about it yet. I was working on my assignment, and I really don't know what I am doing wrong. I am trying to make a simple population model, and I have got most of it to work so far, but when I use the radio buttons, only the normal conditions one activates the graph section.
What I need to do is get each button to display the stars on the graph like the normal button does but I don't know why it isn't doing that already. Any help will be greatly appreciated.

Also, I just noticed, that if you type a new initial mice population, only the normal radio button changes that number, the other boxes just leave the typed in number in the number of mice box. I think both problems are caused by the same problem.

Here is the if statements for the radio buttons and the graph portions of the code(example link at bottom):


if (document.model.conditions[0].checked==true) /* normal conditions */
{
document.model.death.value = 4;
document.model.birth.value = 9;
deathpercent = num2/100;
birthpercent = num3/100;
document.model.mice.value = num1 - num1*deathpercent + num1*birthpercent - owlfood;
}
if (document.model.conditions[1].checked==true) /* cold conditions */
{
document.model.death.value = num2 + 3;

num6 = parceInt(document.model.death.value);
num7 = parceInt(document.model.birth.value);
deathpercent = num6/100;
birthpercent = num7/100;

document.model.mice.value = num1 - num1*deathpercent + num1*birthpercent - owlfood;
}
if (document.model.conditions[2].checked==true) /* fire conditions */
{
document.model.death.value = num2 * 2;

num6 = parceInt(document.model.death.value);
num7 = parceInt(document.model.birth.value);
deathpercent = num6/100;
birthpercent = num7/100;

document.model.mice.value = num1 - num1*deathpercent + num1*birthpercent - owlfood;
}
if (document.model.conditions[3].checked==true) /* exellent conditions */
{
document.model.death.value = num2 - 1;
document.model.birth.value = num3 * 2;

num6 = parceInt(document.model.death.value);
num7 = parceInt(document.model.birth.value);
deathpercent = num6/100;
birthpercent = num7/100;

document.model.mice.value = num1 - num1*deathpercent + num1*birthpercent - owlfood;
}


/* graph portion */

stars = parseInt(document.model.mice.value)/500;

document.model.graph.value = document.model.graph.value + newyear + " "

for ( var count = 1; count <= stars; count = count +1)
{
document.model.graph.value = document.model.graph.value + "*";
}

document.model.graph.value = document.model.graph.value + "\n"


Here is a link to the example webpage if it is needed:
Click Here (http://1200webs.cis.uoguelph.ca/~kvoute/assignment5.html)
Right now, the graph the owls checkbox doesn't do anything.

If anything else is needed, just ask. Thank you so much in advance.

Philip M
03-14-2009, 06:40 PM
At a glance, you have spelled parseInt() throughout as parceInt().

Try correcting that.

It then works, but there is something else wrong with the calculations as I get 7909.0875 mice and 5.859375 owls.

Suggest: num1 = parseInt(document.model.mice.value);
owl = Math.round(num4 * 1.25); // round to nearest integer


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

slvermoondragon
03-14-2009, 06:53 PM
Thank you so much, that was the problem.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum