![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jun 2007
Posts: 93
Rep Power: 2
![]() |
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;
} |
|
|
|
|
|
#2 |
|
Programming Guru
![]() ![]() ![]() |
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." |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jun 2007
Posts: 93
Rep Power: 2
![]() |
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)
Thanks for the help. Last edited by MiKuS; Jul 9th, 2007 at 12:57 AM. Reason: turned on syntax highlighting |
|
|
|
|
|
#4 |
|
Hobbyist Programmer
Join Date: Sep 2007
Location: Sydney - Australia
Posts: 150
Rep Power: 1
![]() |
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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |