В настоящее время я вхожу в введение в класс кодирования, и мы работаем с JS. Мой код хорош, но мне что-то не хватает, потому что для дисконтных выходов я всегда получаю NAN. Кто-нибудь знает, почему это происходит?код всегда возвращается NAN
//Input
var orderAmount = prompt("What is the order amount?");
var contractor = prompt("Are you a contractor? yes/no?");
var employee = prompt("Are you an employee? yes/no?");
var age = prompt("How old are you?");
//Constant
var employeeDisc = .10;
var largeOrderDisc = .05;
var contractorDisc = .20;
var taxRate = .08;
var noTax = 0;
//Calculations
if (orderAmount >= 800) {
var discounta = orderAmount * largeOrderdisc;
}else {
var discounta = 0;
}
if (contractor == "yes") {
var discountc = orderAmount * contractorDisc;
}else if(contractor == "no") {
var discountc = 0;
}
if(employee == "yes") {
var discounte = orderAmount * employeeDisc;
}else if(emplyee == "no") {
var discounte = 0;
}
var discount = discountc + discounte + discounta;
var subtotal = orderAmount - discount;
if (age >= 90){
tax = subtotal * noTax;
}else {
tax = subtotal * taxRate;
}
total = subtotal - tax;
//Output
document.write("Original Price: $" + orderAmount);
document.write("Discount: $" + discount);
document.write("Subtotal: $" + orderAmount);
document.write("Tax: $" + tax);
document.write("Final Price: $" + total);
document.write("Final Price: $" + total);
Извините, что код не компилируется. Теперь он исправлен. Проблема в том, что мой document.write не пишет.
Ну, либо 'discountc',' discounte', либо 'discounta' является' NaN'. –
Вы не должны сравнивать это, сначала конвертируйте в int: '" 15 ">" 10 "-> true; «15»> «9» -> false' – mishik
Пожалуйста, напишите рабочий код (текущий код даже не компилируется) и не предоставите скрипту, чтобы получить более полезные ответы. –