Thread: Java Script Help
-
April 19th, 2009, 07:00 PM #1Junior Member
- Join Date
- Apr 2009
- Posts
- 4
Java Script Help
I need help with my script. I am trying to figure out the lowest maximum heart rate and highest maximum heart rate for exercise. New to javascript any help would be greatly appreciated.
here's what i have so far
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>HeartRate</title>
<script>
var age
max = function maxHeartRate(age)
{
(220-age);
}
</script>
</head>
<body>
<form>
<p>Age<input type="text" id="year" name="Year"></p>
<input type="button" value="Age Input" name="Age">
<onclick = maxHeartRate(age)>
</form>
<script>
var lowestTarget= max*.5
var maxTarget = max*.85
document.write("<p>" + "Max heart rate is " + max + "</p>");
document.write("<p>" + "Maximun Target rate is " + maxTarget + "</p>");
document.write("<p>" + "Lowest max rate is " + lowestTarget + "</p>");
</script>
</body>
</html>
-
April 20th, 2009, 11:30 PM #2
JavaScript Tutorial
I don't want to be discouraging but there are a few errors here. Have you done much html? Have you done any other javascript? Check out the tutorial above and go through that first. Once you make it through that tutorial this should be much easier. I started responding below so you can see some of the stuff that's wrong. I didn't finish though because I found a few more errors and your problems are more just with fundamental understanding than with syntax.
the way you create your function is a little off. maybe javascript is different, as i'm not too familiar with it, but in the languages I use, you can't create a function like that and assign it to a variable. you need to create a function by just getting rid of the "max =" part.
The purpose of a function is to make a block of code that you can call, passing a few arguments with it (in this case, age). Then that function will run and return it's output.
This may not be perfect but it should be closer. Again as I said I don't really know javascript, but i do a lot of programming.
Then you make a call to that function below it like thisCode:function maxHeartRate(age) { return (220-age); }
your html form is a little off. In particular the onclick belongs as an attribute of your submit button, not it's own html tag.Code:max = maxHearRate(21);
The last big error, which is like I said more theoretical is the second script. that script wont' run every time the button is clicked. That run's once when the page is loaded. The text won't automatically change whenever max changes. In other words the script won't sit there and wait for it's variables to change and then change the html. Hope that makes sense.
-
April 21st, 2009, 10:10 AM #3Junior Member
- Join Date
- Apr 2009
- Posts
- 4
Thanks for explaining this sr71000 this is my first time using javascript. I finnaly dulled it down to the simplest possble way i knew how by using a user prompt to get the age and then used statments rather than a function to calculate everything.
here's what i have now
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<body>
<script type="text/javascript">
var age = prompt("What is your age?", "Type your age here");
var max;
var maxTarget;
var lowestTarget;
max=(220-age);
maxTarget=(max*.85);
lowestTarget=(max*.5);
document.write("<p>" + "Max heart rate is " + max + "</p>");
document.write("<p>" + "Max target rate is " + maxTarget + "</p>");
document.write("<p>" + "Lowest target rate is " + lowestTarget + "</p>");
</script>
</body>
</html>
-
April 21st, 2009, 11:29 AM #4
Hey. Did that work for you? I'm not familiar enough with javascript to be able to look at it and just say for sure that it looks like it should work. I don't see why it wouldn't, but just wondering.
-Kevin
-
April 21st, 2009, 03:13 PM #5Junior Member
- Join Date
- Apr 2009
- Posts
- 4
Yes it worked
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Java script help
By Network67 in forum Applications and Operating SystemsReplies: 0Last Post: March 25th, 2005, 04:48 AM -
Java Script - Help!
By rcwabbits in forum Webmastering and ProgrammingReplies: 0Last Post: April 24th, 2003, 10:44 PM -
Java script and IE
By Bill in SD, CA in forum Applications and Operating SystemsReplies: 2Last Post: April 10th, 2003, 02:39 PM



LinkBack URL
About LinkBacks



Reply With Quote

Remember kids, what you share to the public on your facebook can be found by anyone... someone left theirs public and I saw something that I really wish I hadn't. PRIVATE4LIFE
Is It Just Me? v233893843