Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    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.

  • #3
    New to the CF scene
    Join Date
    Mar 2009
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you so much, that was the problem.


  •  

    Posting Permissions

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