Ruriko

06-03-2009, 12:40 PM

I'm having trouble with my script. The script is suppose to calculate how many computers & netbooks it can fit on a bench. A computer can fit 4 per bench (ratio 4:1) and a netbook can fit 5 per bench (5:1). The problem is if I enter 3 computers & 2 netbooks it would give me 2 benches instead of 1. I think I did my maths wrong

<script type="text/javascript">

do {

computer = window.prompt("How many desktop computers do you require?", "0");

computer_num = parseInt(computer);

if (isNaN(computer_num)) /* If the user enters an invalid number it will prompt you to put a valid number */

{

window.alert("Enter a number 0 or above")

}

}

while(isNaN(computer_num));

computer_total = computer/4

do {

netbook = window.prompt("How many netbooks do you require?", "0");

netbook_num = parseInt(netbook);

if (isNaN(netbook_num))

{

window.alert("Enter a number 0 or above")

}

}

while(isNaN(netbook_num));

netbook_total = netbook/5

benches = Math.ceil(computer_total) + Math.ceil(netbook_total);

document.writeln ("<p>" + benches + " benches</p>");

</script>

<script type="text/javascript">

do {

computer = window.prompt("How many desktop computers do you require?", "0");

computer_num = parseInt(computer);

if (isNaN(computer_num)) /* If the user enters an invalid number it will prompt you to put a valid number */

{

window.alert("Enter a number 0 or above")

}

}

while(isNaN(computer_num));

computer_total = computer/4

do {

netbook = window.prompt("How many netbooks do you require?", "0");

netbook_num = parseInt(netbook);

if (isNaN(netbook_num))

{

window.alert("Enter a number 0 or above")

}

}

while(isNaN(netbook_num));

netbook_total = netbook/5

benches = Math.ceil(computer_total) + Math.ceil(netbook_total);

document.writeln ("<p>" + benches + " benches</p>");

</script>