I have been given a task from school.
I’ve been asked to create a program that will keep track of how many books are sold and price of each book.
This program should allow me to enter each book name and price. It should also calculate the total price of the books and display it on screen.
We typically do not provide code for class assignments here, since the whole purpose of such assignments is for you to learn by making use of what your teacher has provided.
Your course tutor is best placed to give you what you need.
If there is anything specific that you would like to know more about though, we’ll be happy to help.
I understand, but it’s not an assignment. Its more of something my former teacher has challenged me too!
I suppose the main thing I wanted to know was how I can build an array that will let me enter any number of books. For example I could enter 2 or 15… I have no idea how to set that up.
Typically you would place the books array somewhere that it can be easily accessed. What used to be done is to make it a global array, but that’s not a good practice these days after we learn that globals should be kept to an absolute minimum, so a good place to store the array is as a property on the form that you use to to enter the information.
var form = document.getElementById('bookSale');
form.books = ;
The thing I don’t quite understand is that after that say for example the user put in 3 books, how would I be able to give them the option to say that’s all today because otherwise the prompt box would keep repeating wouldn’t it?