SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Array application

    Hi folks!

    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.

    I am new to Javascript and no idea where to start, apart from the fact it has to do with Arrays?

    Any help will be much appreciated!

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jamesy23 View Post
    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.

    I am new to Javascript and no idea where to start, apart from the fact it has to do with Arrays?

    Any help will be much appreciated!
    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.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    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.

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jamesy23 View Post
    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.

    HTML Code:
    <form id="bookSale">
    ...
    </form>
    Code javascript:
    var form = document.getElementById('bookSale');
    form.books = [];
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Member
    Join Date
    Mar 2012
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    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.

    HTML Code:
    <form id="bookSale">
    ...
    </form>
    Code javascript:
    var form = document.getElementById('bookSale');
    form.books = [];

    If I use the Javascript code then after " form.books = [] " I would just place the prompt box, right?
    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?

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,684
    Mentioned
    99 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by jamesy23 View Post
    If I use the Javascript code then after " form.books = [] " I would just place the prompt box, right?
    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?
    It would be best to flowchart out all of the possible behaviour of someone using this. That way, once you fully know what is expected, you can craft together a working solution that meets those needs.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •