Results 1 to 5 of 5

Thread: HELP Needed with Assignment

  1. #1
    Join Date
    Oct 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default HELP Needed with Assignment

    So I need some help badly...I don't want anyone to do the assignment for me, but to guide me into figuring it out...I think that I'm over thinking this, but I just can't seem to figure out which codes to use for everything or where to even start...I have tried to read it over and over again, and for some reason I'm just not getting it...

    Keep in mind that I'm pretty new to JS, and we are only on the 3rd chapter, I hope someone can help...

    Here it is:

    The American Heart Association recommends that when you exercise, you stay within 50 to 85 percent of your maximum heart rate. This range is called your target heart rate. One common formula for calculating maximum heart rate is to subtract your age from 220. Create a web page that you can use to calculate your target heart rate. Use a form that contains a text box in which users can enter their age and a command button that uses an "onclick" event handler to call a function named "calcHeartRate(). Within the calcHeartRate(), include a statement that calculates the maximum heart rate and assigns the result to a variable. Use two other statements that calculate the minimum (50%) and maximum (85%) target heart rates. To calculate the minimum target heart rate, you use the the formula "maximum_heart_rate*.5" and to calculate the maximum target heart rate, you use the formula "maximum_heart_rate*.85". After you calculate the minimum and maximum target heart rates, display the result in another text box in the form. For example, for someone 35 years old, the target heart rate text box should display "92 to 157 beats per minute".

    Thanks,
    Jenn

  2. #2
    Join Date
    Feb 2008
    Location
    Cebu City Philippines
    Posts
    1,160
    Thanks
    17
    Thanked 277 Times in 275 Posts

    Default

    You should show to us the code to which you're stumped at. Anyway, I'm bored:
    HTML Code:
    <script type="text/javascript">
    function calcHeartRate()
    {
    var max=0,min=0,result=0,sub=220, // Initialize some variables
    age=document.getElementById('age'), // Textbox that accepts the age
    show=document.getElementById('result'); // Textbox to show the result
    age=Number(age.value);
    if(isNaN(age)) alert('Please provide a number.'); // If not a number
    else
    	{
    	max=(sub-age)*(0.85); // Get the max heart beat
    	min=(sub-age)*(0.5); // Get the min heart beat
    	max=(Math.floor(max)); // Round downwards to the nearest integer
    	min=(Math.floor(min)); // Round downwards to the nearest integer
    	show.value=min+' to '+max+' beats per minute';
    	}
    }
    </script>
    <label for="age">Age: </label><input type="text" id="age">
    <input type="button" value="Calculate Heart Beat" onclick="calcHeartRate()">
    <input type="text" id="result" readonly="readonly" style="width:200px;">
    Learn how to code at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph!

  3. #3
    Join Date
    Oct 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Rangana,

    I would have included the code, but I hadn't actually started anything. This is why I'm lost I looked at your code, and I'm not sure that I understand much of it...some of it doesn't look like stuff that I have learned as of yet.

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Don't take this as unfriendly or that we don't want to help you, but there is a reason that this is homework. You're supposed to learn how to do it, and that is by practicing. If you have questions, ask them, but don't just type up the question you're asked and ask us to do it for you or tell you how to do it.
    Programming can be challenging, but you won't learn it unless you do the hard work and put the time in yourself.
    That said, if you have specific questions, we can help. You're supposed to be confused, but it's ok. Just try and fail if you have to, but then try again, and you'll probably succeed.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Oct 2008
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    As I said in my first post....

    [QUOTE]So I need some help badly...I don't want anyone to do the assignment for me, but to guide me into figuring it out...I think that I'm over thinking this, but I just can't seem to figure out which codes to use for everything or where to even start...[QUOTE]

    I didn't ask for someone to do it for me...I wanted a starting point, I didn't use the code provided as most of it was nothing that we had learned as of yet, so I used it as a starting point and did my own...

Bookmarks

Posting Permissions

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