Hi,
I need help in how to get my program to output the
information required.
I want the program to display the information as shown below:
book1 sales: a—% of total sales: b%…of total
buyers: c%
book2 sales: a—% of total sales: b%…of total
buyers: c%
book3 sales: a—% of total sales: b%…of total
buyers: c%
Book with highest sales is ..d.. with ..e.. sales.
• a = book sales figure (entered by user)
• b = percentageSales1Array
• c =percentageSales2Array
• d = book with the highest sales
• e = sales figure of book with highest sales
How do i declare the percentage and variable in order to get the code working? What am i doing wrong?
Please see code written so far. Help needed.
Thanks
<HTML>
<HEAD>
<TITLE>
Book_sales
</TITLE>
<SCRIPT LANGUAGE = “JavaScript”>
/* Program to calculate total number of books sold and display the book with highest sales
[B]var
[B]var
[B]var
[B]var
[B]var
[B]var
[B]var
/* loop to read in and add the 8
books to book array
[B]for[B]var
{
totalBuyers = parseFloat(window.prompt(‘Please enter the total number of buyers’,”));
totalSales = parseFloat(window.prompt(‘Please enter the total number of all books sold’,”));
[B]for[B]var
{
bookSalesArray = parseFloat(window.prompt(‘Please enter the sales for book ‘ + (count + 1),”));
/* determines book with highest sales
highestBookSalesIndex = 0;
[B]for[B]var
{
[B] if
{
highestBookSalesIndex = book;
}
}
}
/* calculates percentage of each book sold using total sales of all the books
[B]for[B]var
{
percentageSales1Array[book] = Math.round2dp((bookSalesArray[book] / totalSales) * 100)
}
/*/
[B]for[B]var
{
percentageSales2Array[book] = Math.round2dp((bookSalesArray[book] / totalBuyers)
}
}
document.write(‘Total buyers: ‘ + ” + totalBuyers + ‘Total sales: ‘ + ” + totalSales + ‘<BR>’);
document.write(‘book1 ‘ + ” + ‘sales: ‘ + bookSalesArray[book] + ” + ‘% ‘ + ‘of total sales: ‘ + percentageSales1Array[book + 1] + ” + ‘% ‘ + ‘of total buyers: ‘ + percentageSales2Array[book + 1] + ” + ‘% ‘ + ‘<BR>’);
document.write(‘book2 ‘ + ” + ‘sales: ‘ + bookSalesArray[book] + ” + ‘% ‘ + ‘of total sales: ‘ + percentageSales1Array[book + 1] + ” + ‘% ‘ + ‘of total buyers: ‘ + percentageSales2Array[book + 1] + ” + ‘% ‘ + ‘<BR>’);
document.write(‘book3 ‘ + ” + ‘sales: ‘ + bookSalesArray[book] + ” + ‘% ‘ + ‘of total sales: ‘ + percentageSales1Array[book + 1] + ” + ‘% ‘ + ‘of total buyers: ‘ + percentageSales2Array[book + 1] + ” + ‘% ‘ + ‘<BR>’);
document.write(‘book4 ‘ + ” + ‘sales: ‘ + bookSalesArray[book] + ” + ‘% ‘ + ‘of total sales: ‘ + percentageSales1Array[book + 1] + ” + ‘% ‘ + ‘of total buyers: ‘ + percentageSales2Array[book + 1] + ” + ‘% ‘ + ‘<BR>’);
document.write(‘book5 ‘ + ” + ‘sales: ‘ + bookSalesArray[book] + ” + ‘% ‘ + ‘of total sales: ‘ + percentageSales1Array[book + 1] + ” + ‘% ‘ + ‘of total buyers: ‘ + percentageSales2Array[book + 1] + ” + ‘% ‘ + ‘<BR>’);
document.write(‘Book with highest sales is ‘ + highestBookSalesIndex[book] + ” + ‘with ‘ + highestBookSalesIndex + ‘% ‘ + ‘<BR>’);
</SCRIPT>
</HEAD>
<BODY>
</BODY>
</HTML>