I didn't understand what the second statement (totalEstimate -= guestsCost in the "calcGuests" function is for?
Please someone explain to me as I'm a beginner.
var guestsCost=0;
var limousinesCost=0;/* this variable does nothing */
var liveMusicCost=0;/* this variable does nothing */
var flowersCost=0;/* this variable does nothing */
var totalEstimate=0;
function calcGuests(){
totalEstimate -= guestsCost; /* for the very first calculation this line has no sense because it is equal to 'totalEstimate = 0 - 0;' */
guestsCost = document.details.numGuests.value * 65;/* this means 'guestsCost = here_goes_what_you_type_in_the_first_form_input * 65' */
totalEstimate += guestsCost;/* this is equal to 'totalEstimate = totalEstimate + guestsCost' */
document.estimate.cost.value = "$" + totalEstimate;/* this makes a string from the dollar sign and the calculation result and puts it into the second form's INPUT element named 'COST' */
}
use [code]YOUR CODE GOES HERE[/code] or burn in Hell
first time,it's mean totalEstimate = totalEstimate-guestsCost;// totalEstimate=0-0;
result:
totalEstimate=0+first time input numGuest*65;
second time,your change the input numGuests,the js will run again,but the varables is global,
totalEstimate!=0
totalEstimate=first time input numGuest*65+second time input numGuest*65;//wrong answer!
you must make totalEstimate=0 as the first time
Bookmarks