Cents to dollars program won't work...PLEase Help

N

nyy

this program is supposed to give the user the ability to enter numbers
in cents and tell you how many dollars you have. PLease anybody can
tell me what's wrong. Thx.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Cents to Dollars</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function calcCents {
var cents = document.money.cents.value;
var dollars = 0;
var dollars = cents / 100;
var change = cents % 100;
if (change != 00)
window.alert("The number of cents you entered is equal to $" +
dollars + ".00");
else
window.alert("The number of cents you entered is equal to $" +
dollars);

}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body>
<form name="money" action="">
<p>Cents: <input type="text" name="cents" /><br />
<input type="button" value="Cents to Dollars" onclick="calcCents();"
/></p>
</form>
</body>
</html>
 
L

Lee

nyy said:
this program is supposed to give the user the ability to enter numbers
in cents and tell you how many dollars you have. PLease anybody can
tell me what's wrong. Thx.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Cents to Dollars</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS

There are no incompatible browsers in use anymore.
You don't need to hide scripts.
function calcCents {

Function declarations require a formal argument list in
parentheses, even if there are no formal arguments:

function calcCents() {


var cents = document.money.cents.value;
var dollars = 0;
var dollars = cents / 100;
var change = cents % 100;
if (change != 00)

The sense of this test is backwards, and there is no
reason to write the value zero as 00.

if (change == 0)
 
W

web.dev

nyy said:
this program is supposed to give the user the ability to enter numbers
in cents and tell you how many dollars you have. PLease anybody can
tell me what's wrong. Thx.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Cents to Dollars</title>
<script type="text/javascript">
<!-- HIDE FROM INCOMPATIBLE BROWSERS
function calcCents {

You have a syntax error here. It should be:

function calcCents() {

You were missing the ().
var cents = document.money.cents.value;
var dollars = 0;
var dollars = cents / 100;

You already declared dollars as a variable. There's no need for
multiple declarations.

You wanted just the number of dollars? Then:

dollars = Math.floor(cents / 100);
var change = cents % 100;
if (change != 00)
window.alert("The number of cents you entered is equal to $" +
dollars + ".00");
else
window.alert("The number of cents you entered is equal to $" +
dollars);

If you wanted just the number of dollars, then you don't even need to
check the change, right?
}
// STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body>
<form name="money" action="">
<p>Cents: <input type="text" name="cents" /><br />
<input type="button" value="Cents to Dollars" onclick="calcCents();"
/></p>
</form>
</body>
</html>

Hope this helps.
 
S

Stephen Chalmers

web.dev said:
If you wanted just the number of dollars, then you don't even need to
check the change, right?

I expect that depends upon what format his teach... oops - I mean he prefers.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Please Help? 0
Help please 8
Survey details won't go through using php, ajax, Mysql 0
I dont get this. Please help me!! 2
Help with code 0
Need help again please 19
Help with my responsive home page 2
Help :( 3

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top