Event handling web fundamentals web ticketing JS final step
Hi guys, I need help to make the final step of the code repo even handling web ticketing really works when writing a number into the input fields of adults and children (I'm new in this), to take the values and perform the calculation. The description is: Event Handling Time to finalize our price calculation and add the functionality to our form! Tasks: 1. Add the window.onload event handler. 2. Inside it, take the reference to the buy button (assign it an id, so you can take its reference). 3. Handle the click event of the buy button: inside the handler, take the references of the adults and children text fields using their ids. 4. Calculate the total price of the tickets using the calc() function. 5. Output the price to the screen using the alert() function. Hint: Take the current value using the .value property: here is how your window.onload event handler should look like: window.onload = function() { let btn = document.getElementById("buyBtn"); btn.onclick = function() { let adults = document.getElementById("adults").value; let children = document.getElementById("children").value; let price = calc(adults, children); alert(price); } } Here is my code https://www.sololearn.com/compiler-playground/WKj9jk7tG5Gj/ /* Creating variables */ let adults = parseInt(document.getElementById("adults").value); let children = parseInt(document.getElementById("children").value); let price = (adults * 12) + (children * 5); /*console.log(price);*/ /* Reviewing if the input on aduls and children, is a negative number, if it is, will be changed to 0 */ if (adults < 0) { adults = 0; } if (children < 0) { children = 0; } /* Crating a program to print the tickets, for the adults */ for(let i = 1; i <= adults; i++) { console.log("Ticket #" + i); } /* Creating a function to replace the price calculation */ /*let adults = document.getElementById("adults"); let children = document.getElementById("children");*/