Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-14-2009, 05:02 PM   PM User | #1
slvermoondragon
New to the CF scene

 
Join Date: Mar 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
slvermoondragon is an unknown quantity at this point
Javascript Question/Problem

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):
Code:
        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
Right now, the graph the owls checkbox doesn't do anything.

If anything else is needed, just ask. Thank you so much in advance.
slvermoondragon is offline   Reply With Quote
Old 03-14-2009, 05:40 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.

Last edited by Philip M; 03-14-2009 at 05:58 PM..
Philip M is online now   Reply With Quote
Old 03-14-2009, 05:53 PM   PM User | #3
slvermoondragon
New to the CF scene

 
Join Date: Mar 2009
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
slvermoondragon is an unknown quantity at this point
Thank you so much, that was the problem.
slvermoondragon is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:41 AM.


Advertisement
Log in to turn off these ads.