+ 2

JS on Ticketing Website

Hi all. Not sure if Im overthinking the question but the Javascript part of my code doesnt seem to interact with the form I have made with HTML. There isnt any reference to the form in the question and I dont recall this module teaching anything about linking the JS to the HTML form. When outputting to the console, I just get "18" which is the 2 prices in the question added together. The module just taught basic maths in variables... here is the question: Tasks: 1. Declare two variables, one called adults, the other one children, and initialize them to some values, for example 42 and 8. 2. Declare another variable called price, which will hold the total price of the tickets. 3. Calculate the price of all tickets by using the following prices: Adults: $12, Children: $6. 4. Output the price value to the console. The Form Code: <section id="buy"> <form> <div class="form-section"> <label for="Adults"><b>Adults:</b></label><br> <input type="number" id="Adults"></input> </div> <div class="form-section>"> <label for="Children"><b>Children:</b></label><br> <input type="number" id="Children"></input> </div> <div class="form-section"> <input type="button" value="Buy"></input><br> </div> </form> </section> The JS Code - (doesnt seem to be storing as variables, just assigning a value) let adults = 12; let children = 6; let price = (adults)+(children); console.log(price); ----------- Console:18 Am I doing something wrong or is the question missing something or should the module have taught something else which seems to be the missing piece? Many thanks

19th Mar 2022, 9:39 PM
Thomas Murphy
3 Answers
+ 1
12 you assigned is number of adults. For every one ticket id $12 so total 12*12 For children : 6*6 Total_price = adult*12 + children*6 ;
19th Mar 2022, 9:54 PM
Jayakrishna šŸ‡®šŸ‡³
+ 1
Thanks for the reply and I understand your answer. Why does the question ask to initialize the variables to a random number? (first part of the question). Surely the idea of a variable in this instance is to assign it to an input value for it to make the calculation? Or is it just wanting me to use the initialized values to make the calculation? Because I cant see how any of this links to the form this is being made for. Many thanks again @Jayakrishnain
19th Mar 2022, 10:07 PM
Thomas Murphy
0
Am not sure about it but those are for only pro members practice. It may be first, step now... may explained in next lesson how to use form.. Finally it made to complete a repo code.I think. ....You're welcome.....
19th Mar 2022, 10:13 PM
Jayakrishna šŸ‡®šŸ‡³