Why am I getting a javascript NaN error message? -
doing project intro javascript class , can't quite figure out why isn't working. can me out? here code assignment.
//declare variables var guestsperroom; var discount; var goodview; var totalcost; var costpernight; var membership; //prompt user enter info based on needs guestsperroom = prompt("how many guests staying in room? (max 6)"); discount = prompt("are member of aaa?"); goodview = prompt("would room view? (10% price increase)"); //calculate guests needs total cost totalcost = number(totalcost); discount = number(discount); costpernight = number(costpernight); //output users total cost if (guestsperroom === 1 || guestsperroom === 2) { costpernight = 50; if (membership === 'y') { discount = costpernight * 0.85; } else if (membership === 'n') { discount = costpernight; } if (goodview === 'y') { totalcost = costpernight * discount * 1.1;‹ } else if (goodview === 'n') { totalcost = costpernight * discount; } } document.write("total cost per night $" + totalcost);
when run program, hoping phrase "total cost per night $50(or whatever total cost be). can tell me i'm doing wrong? guess totalcost variable not defined, cannot figure out.
the problem trying convert number non numeric answers these 2 questions:
discount = prompt("are member of aaa?"); goodview = prompt("would room view? (10% price increase)"); discount = number(discount); costpernight = number(costpernight);
of course answers not numbers. hence error.
Comments
Post a Comment