/    Sign up×
Community /Pin to ProfileBookmark

Help me get my code working!

<html>
<head>
<title>Age Calculator</title>
<script type=”text/javascript”>
<form id=”calculator”>
<label for=”age”>How old are you in years? </label>
<input id=”age” type=”number” min=”0″ />
</form>
<p>You are (at least) <span id=”result”>0</span> days old.</p>
{
$(document).ready(function() {
$(“#age”).change(function(event) {
age = $(“#age”).val();
$(“#result”).text(addCommas(Math.floor(age * 365.25)));
});
});

function addCommas(nStr)
{
nStr += ”;
x = nStr.split(‘.’);
x1 = x[0];
x2 = x.length > 1 ? ‘.’ + x[1] : ”;
var rgx = /(d+)(d{3})/;
while (}rgx.test(x1)) {
x1 = x1.replace(rgx, ‘$1’ + ‘,’ + ‘$2’);
}
return x1 + x2;
}
</script>
</head>
</body>
</html>

I am trying to make an age calculator, so that the page displays a box and you type in how old you are in the box and it gives you your age in DAYS and this is what I have so far, but its not working and I dont know whats wrong. I also want to add like If the AGE is less then ZERO it wont work, or if the Age is greater than 120 It wont work. How do I add that line so it makes the program not work or say type in another age or something like that? beginner with java here ><

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@KorApr 04.2011 — $(), ready() and other methods there [I]are not JavaScript native methods[/I]. They are part of a JavaScript framework/library notation, probably JQuery, [I]whose core code you omitted to load[/I], thus your code has no chances to work. It's like a car with no engine.

Do yourself a favor and learn JavaScript language before using a JavaScript library. And then learn how to use a JavaScript library.
×

Success!

Help @Zatox 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...