Defining Javascript Function
Ive been given a piece of Javascript code to edit for taking inputs from a HTML form with 2 different inputs and outputting the sum of the two inputs to the "alert" that pops up on the screen (i made the form as part of the course). The task is a 5 part question and Im stuck on one part which asks you to define the calc() function which you will see in the code below. I think ive got the bits of HTML for the form all in order, but how to define the calc() function is really confusing me. I understand the syntax for defining a function, but I cant for the life of me figure what to put, or even where to put it in this example?! Here is the code: 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); } } Any help or advice much appreciated. I've spent 3 evenings Googling and guessing and going back through notes and trying different things and I'm fed up now :(