Help me in javascript & jquery

I want the code for this:

What assignment is this for?

Can you share the code you have so far and what specifically you are having trouble with?

Also, a link to the original assignment would be helpful.

Is it the design only? Because for the functionality you would need a server and a db aswell as some authentication.

1 Like

Is this for an interview?
And this is a rather large project to just say “help me with.” Is there a specific smaller chunk of it that you can point to and say you need help understanding or working out.

Well, to your snippet here, rather than variables for each seat level, I’d probably create an object to contain them all. something like this:

const seatLevels = {" Class C": 5, " Class B": 10, "Class A": 20, "VIP": 40};

then when you get the input from the user, which will be from a form, you can easily take the parameters and:

const total = seatLevels[classChoice] * quantity * (hasPromo ? .75 : 1);

of course don’t forget to validate the quantity to make sure it is <= 5

You can multiply them, but just make sure they are numbers before you do. There are two convenient ways to do that: one is to wrap it in the Number() function, the other one is to prefix it with a +:

Number(seatFunction) * Number(ticketFunction)


 +seatFunction * +ticketFunction

It’s really hard if you dont provide what you have done so far or where you want to show it. Just naming the requirements for the product without showing any code of where you have the problems, it’s really hard to try and help you finding a solution.

1 Like

I don’t much care for globals, but using what you have so far, I would probably add a button and a spot for the total price to your html. Something like this:

<button id="get-total">Get Total</button>
<h2 id="total-price">0</h2>

Then in the javascript I’d add an event handler to the button that, on clicking it, changed the total price’s innerText value to s * t (of course you want to validate that s and t have been set first. Or as an easier option just initialize them each to 0.)

But that’s just one way to do it, the beauty of coding is there are many ways to do the same thing. Not always necessarily “better” or “worse” just different.