Kinda confused

12-16-2010, 03:33 PM

I am new to java and tried writing the code for practice but it doesn't seem to work

<html>

<Head>

<title>Discount</title>

<script language ="Javascript">

<!--

function CalculateBalance(numItems,totPrice,discount)

{ var balance;

balance = (1 - discount)*totPRice;

alert ('Your balance is $'+balance +' Thank You.');

document.write("<br>YOu bought "+ numItems+" items for $"+totPrice);

document.write("<br>Your balance is $"+ balance+" your discount was"+discount*100+"% Thank you");

}

//-->

</script>

</head>

<script language ="Javascript">

<!--

var discount;

var numItems = parseInt(prompt('HOw many time did you buy [ >=12 is 20% and >= 6 is 10% discount]',"0"));

alert ('You bought '+numItems +' items.');

document.write("You bought "+ numItems+" items.");

var totPrice = parseFloat(prompt('The total price that you paid was',"0.0"));

if(numItems >= 12) {discount = .2;}

else if (numItems >=6) {discount+ .1}

else {discount = 0;}

CalculateBalance(numItems,totPrice,discount);

//-->

</script>

</html>

It only prints to the screen the number of items I bought

<html>

<Head>

<title>Discount</title>

<script language ="Javascript">

<!--

function CalculateBalance(numItems,totPrice,discount)

{ var balance;

balance = (1 - discount)*totPRice;

alert ('Your balance is $'+balance +' Thank You.');

document.write("<br>YOu bought "+ numItems+" items for $"+totPrice);

document.write("<br>Your balance is $"+ balance+" your discount was"+discount*100+"% Thank you");

}

//-->

</script>

</head>

<script language ="Javascript">

<!--

var discount;

var numItems = parseInt(prompt('HOw many time did you buy [ >=12 is 20% and >= 6 is 10% discount]',"0"));

alert ('You bought '+numItems +' items.');

document.write("You bought "+ numItems+" items.");

var totPrice = parseFloat(prompt('The total price that you paid was',"0.0"));

if(numItems >= 12) {discount = .2;}

else if (numItems >=6) {discount+ .1}

else {discount = 0;}

CalculateBalance(numItems,totPrice,discount);

//-->

</script>

</html>

It only prints to the screen the number of items I bought