Javascript help

Associate
Joined
4 Mar 2010
Posts
206
Hi,

new to the forum in a way that i read a lot but hide in the shadows :rolleyes:

I've been set a task by my tutor for our javascript module in which ive to create a program for a small company. im a total newby at javascript and im currently just recycling old code i have.

my task:

come up with 10 products, give them each and id number (1-10) and a price.
the user can then select what product they wish to purchase by the id number and select the quantity. once they have done this they can then see an invoice where they must enter their firstname, lastname and address. VAT is taken into consideration when calculating the total costs also.

im not asking for anyone to do this for me but im sure im capable of doing this on my own when i get past the part im stuck at.

Im curious as to how i can make my program prompt the user to put their personal details in and then add that information to the invoice. should i be doing this with an array or??

if there are any javascript pros out there and are willing to help me out id appreciate it. :)

rosso5792
 
How much JS have you done so far? Have you touched on any of the Object Oriented side of it?

I'd do the following:

Products - create objects for each product, e.g.:

Code:
function Product(id, price) {
    this.idNumber = id;
    this.price = price;
}

Then create an array of these objects:

Code:
var productArray = new Array(10);
for(var i=0; i<10; i++) {
    productArray[i] = new Product(i, 100);
}

For doing the UI bit I'm guessing this'll be running in a web browser? So the easiest thing would be to use Prompts - see http://www.w3schools.com/JS/js_popup.asp

Hope this helps. I've not tested any of this code but it should give you some idea.
 
Back
Top Bottom