/    Sign up×
Community /Pin to ProfileBookmark

Some newb problems

I have some files that I am working on for a class. I am a little lost. The first one is supposed to calculate min and max heart rate. The second calculates shipping, and the third checks for the leap year. I have seen examples of these on the net, but I am not about just cutting and pasting. I want to understand what is going on and what I am doing wrong. So, what am I missing?

[B]Heart Rate[/B]:
<script type=”text/javascript”>
/* <![CDATA[ */
var age = 0;
function calcheartrate(value) {
var max = 220 – age;
var maxtarget = max * .85;
var mintarget = max *
.5;
document.write(“<p>” + mintarget + ” to ” + maxtarget + ” beats per minute”);
}
/* ]]> */
</script>
</head>

<body>]
<div style=”text-align: center”>
<form name=”Heartrate” action=””>
<input type=”text” name=”Input” /><br />
<input type=”button” name=”calc” value=” Calculate Heart Rate ” onclick=”calcheartrate(eval(document.Heartrate.Input.value));” />
<input type=”button” name=”clear” value=” Clear ” onclick=”document.Heartrate.Input.value=”; inputString=”” />
</form>
</div>
</body>

[B]Shipping[/B]:
<script type=”text/javascript”>
/* <![CDATA[ */
var input = “”;
var percent = .10; totalshipping = 0; price = 0;
function calcshipping(price) {
input += price;
document.Shipping.input.value = price;
if (price <= 25)
totalshipping += 1.5;
if (price > 25)
totalshipping = price * percent / 100;
window.alert(totalshipping);
}
/*
]]> */
</script>
</head>

<body>
<h1></h1>
<div style=”text-align: center”>
<form name=”Shipping” action=””>
<input type=”text” name=”input” /><br />
<input type=”button” name=”calcship” value=”Calculate Shipping” onclick=”calcshipping(eval(document.Shipping.input.value=”));” />
<input type=”button” name=”clear” value=”Clear” onclick=”document.Shipping.input.value=”)); price=”” />
</form>
</div>

</body>
</html>

[B]Leapyear[/B]:

<script type=”text/javascript”>
/* <![CDATA[ */
var input = “”;
function checkyear(year) {
var year = input;
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0));
window.alert(“<p>This is a leap year</p>”);
else
window.alert(“<p>This is not a leap year</p>”);
}
/* ]]> */
</script>
</head>

<body>
<div style=”text-align: center”>
<form name=”Leapyear” action=””>
<input type=”text” name=”Input” /><br />
<input type=”button” name=”calc” value=” Check Year ” onclick=”checkyear(eval(document.Leapyear.input.value))” />
<input type=”button” name=”clear” value=” clear ” onclick=”document.Leapyear.Input.value=”; input=”” />
</form>
</div>
</body>

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@marcusamiJun 04.2008 — your passing value and not doing anything with it in this function at all

value is supposed to be age right? make it 220-value; if thats what the user is inputing and it will work.

var age = 0;

function calcheartrate(value) {

var max = 220 - age;

var maxtarget = max * .85;

var mintarget = max *
.5;

document.write("<p>" + mintarget + " to " + maxtarget + " beats per minute");

}
[/QUOTE]



on SHIPPING input is a keyword and cant be used as a var

good luck

regards

Marcus
Copy linkTweet thisAlerts:
@marcusamiJun 04.2008 — heres this with commenting

you didnt need input;

u had a problem in ur form

u had value='';

so it was passing nothing


<html>

<head>

<script type="text/javascript">

/* <![CDATA[ */

var percent = .10; totalshipping = 0; price = 0;

function calcshipping(price) {

if (price <= 25) //if price of item is or is under 25 shipping = 1.5

totalshipping = 1.5;

if (price > 25) //if price of item is over 25 shipping .10/100 % of price

totalshipping = price * percent / 100; // i dont think u need to percent / 100 i think its just price * percent

document.Shipping.inputt.value = (price + totalshipping); //total value = price + shipping

window.alert(totalshipping);// alert shipping price

}

/* ]]> */

</script>

</head>

<body>

<h1></h1>

<div style="text-align: center">

<form name="Shipping" action="">

<input type="text" name="inputt" /><br />

<input type="button" name="calcship" value="Calculate Shipping" onclick="calcshipping(eval(document.Shipping.inputt.value));" />

<input type="reset" name="clear" value="Clear" />

</form>

</div>

</body>

</html>

[/QUOTE]
Copy linkTweet thisAlerts:
@shea19authorJun 05.2008 — Thanks for the help. I really appreciate it.
×

Success!

Help @shea19 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...