PDA

View Full Version : HELP Needed with Assignment

Juniper79
10-07-2008, 11:23 PM
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

rangana
10-08-2008, 12:34 AM
You should show to us the code to which you're stumped at. Anyway, I'm bored:

<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);
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()">

Juniper79
10-08-2008, 03:27 AM
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.

djr33
10-09-2008, 01:39 AM
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.

Juniper79
10-11-2008, 05:41 AM
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...