Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 5th, 2007, 11:01 PM   #1
MiKuS
Programmer
 
Join Date: Jun 2007
Posts: 84
Rep Power: 1 MiKuS is on a distinguished road
Help with Calculator

I currently am making a calculator (to learn javascript better)

it's a karvonen heart rate calculator which calculates what your target heart rate BPM should be for a percentage workout, the formula is as follows:

(maximum heart rate = maximum achievable heart rate)
(minimum heart rate = heart rate measured just after waking up)

maximum heart rate - minimum heart rate * workout percentage + minimum heart rate = target bpm

ok, now i can get the formula kinda working.. the poblem i have is with this code:

targetHeartRateLow=Math.floor((maxHeartRate-minHeartRate)*percentZoneMin/100)+minHeartRate;

instead of adding minHeartRate it joins it like two strings like 4499 instead of showing 143 (44+99). Below is the code i'm using

function calc(form){
var maxHeartRate;
var minHeartRate;
var percentZoneMin;
var percentZoneMax;
var targetHeartRateLow;
var targetHeartRateHigh;

minHeartRate=form.rest_hr.value;
maxHeartRate=form.max_hr.value;
percentZoneMin=form.percent_zone1.value;
percentZoneMax=form.percent_zone2.value;

targetHeartRateLow=Math.floor((maxHeartRate-minHeartRate)*percentZoneMin/100)+minHeartRate;
targetHeartRateHigh=Math.floor((maxHeartRate-minHeartRate)*percentZoneMax/100)+minHeartRate;
form.target_hr1.value=targetHeartRateLow;
form.target_hr2.value=targetHeartRateHigh;

}
MiKuS is offline   Reply With Quote
Old Jun 6th, 2007, 8:09 AM   #2
Infinite Recursion
Programming Guru
 
Infinite Recursion's Avatar
 
Join Date: Jul 2004
Location: United States
Posts: 3,436
Rep Power: 7 Infinite Recursion is on a distinguished road
Send a message via MSN to Infinite Recursion Send a message via Yahoo to Infinite Recursion
look into using the parseInt function.
(http://www.w3schools.com/jsref/jsref_parseInt.asp)
__________________
http://jasonpowers.net

"There are a thousand hacking at the branches of evil to one who is striking at the root."
Infinite Recursion is offline   Reply With Quote
Old Jul 9th, 2007, 12:44 AM   #3
MiKuS
Programmer
 
Join Date: Jun 2007
Posts: 84
Rep Power: 1 MiKuS is on a distinguished road
it's been a while since i last posted (been busy) but i got it in the end, here is the code i used.

javascript Syntax (Toggle Plain Text)
  1. //Work Out Heart Rate Min - Max
  2. function calc(form){
  3. var maxHeartRate;
  4. var minHeartRate;
  5. var percentZoneMin;
  6. var percentZoneMax;
  7. var targetHeartRateLow;
  8. var targetHeartRateHigh;
  9. //Get form values
  10. minHeartRate=parseInt(form.rest_hr.value,10);
  11. maxHeartRate=parseInt(form.max_hr.value,10);
  12. percentZoneMin=form.percent_zone1.value;
  13. percentZoneMax=form.percent_zone2.value;
  14. //Run our calculation
  15. targetHeartRateLow=Math.floor((maxHeartRate-minHeartRate)*percentZoneMin/100)+minHeartRate;
  16. targetHeartRateHigh=Math.floor((maxHeartRate-minHeartRate)*percentZoneMax/100)+minHeartRate;
  17. //update our form
  18. form.target_hr1.value=targetHeartRateLow;
  19. form.target_hr2.value=targetHeartRateHigh;
  20.  
  21. }

Thanks for the help.

Last edited by MiKuS; Jul 9th, 2007 at 12:57 AM. Reason: turned on syntax highlighting
MiKuS is offline   Reply With Quote
Old Sep 23rd, 2007, 6:46 PM   #4
Grich
Hobbyist Programmer
 
Grich's Avatar
 
Join Date: Sep 2007
Location: Sydney - Australia
Posts: 137
Rep Power: 1 Grich is on a distinguished road
I know it's over, but you could also use the Number() function as well as the parseInt() function.
It brings back a float / double.
Grich is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
[vbasic] Calculator dwizzle13 Existing Project Development 13 Oct 12th, 2006 5:44 PM
Programming video game to TI calculator? magus57 Project Ideas 20 May 5th, 2006 10:19 PM
Calculator Multiple Operations? jl13 C# 5 Oct 12th, 2005 4:32 PM
Javascript calculator narroweyes JavaScript and Client-Side Browser Scripting 7 Jul 30th, 2005 12:46 PM
simple calculator Jessehk Show Off Your Open Source Projects 4 May 25th, 2005 4:39 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 4:53 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC