在语法错误上使用JavaScript的困难

时间:2016-10-14 20:33:23

标签: javascript

我得到这个......未知的SyntaxError:缺少)在参数列表之后...当我尝试输入此代码时,我无法弄清楚如何修复它。

// flight_costs.js

function flightCosts() {

    const cost_per_checked_bag = 50; 
    const typical_flight_speed = 575;
    const hours_in_airport = 5; 

    var traveler_payrate_per_hour = Number(document.getElementById("traveler_payrate_per_hour").value);
    console.log("traveler_payrate_per_hour" + traveler_payrate_per_hour);
    var number_of_travelers = Number(document.getElementById("number_of_travelers").value);
    console.log("number_of_travelers" + number_of_travelers);

    //Flight Costs
    var miles_flying = Number(document.getElementById("miles_flying").value);
    console.log("miles_flying" + miles_flying);
    var flight_cost = Number(document.getElementById("flight_cost").value)
    console.log("flight_cost" + flight_cost);
    var flight_transit_cost = Number(document.getElementById("flight_transit_cost").value);
    console.log("flight_transit_cost" + flight_transit_cost);
    var flight_discount = Number(document.getElementById("flight_discount").value);
    console.log("flight_discount" + flight_discount);
    var flight_amenities = Number(addCheckboxValues("flight_amenities") ||0;
    console.log("flight_amenities" + flight_amenities);
    var checked_bags_per_traveler = Number(document.getElementById("checked_bags_per_traveler").value);
    console.log("checked_bags_per_traveler" + checked_bags_per_travelers);
    var in_flight_amenities = Number(addCheckboxValues("in_flight_amenities") ||0;
    console.log("in_flight_amenities" + in_flight_amenities);

    var total_traveler_flight_cost = flight_cost * number_of_travelers;
    console.log("total_traveler_flight_cost" + total_traveler_flight_cost);

    var time_of_flight = miles_flying / typical_flight_speed;
    console.log("time_of_flight" + time_of_flight);

    var total_amenities = (flight_amenities + in_flight_amenities) * number_of_travelers;
    console.log("total_amenities" + total_amenities);

    var total_payrate_cost = (traveler_payrate_per_hour * (time_of_flight * 2) + hours_in_airport) ) * number_of_travelers;
    console.log("total_payrate_cost" + total_payrate_cost);

    var total_flight_checked_bags_cost = check_bags_per_traveler * cost_per_checked_bag * number_of_travelers;
    console.log("total_flight_checked_bags_cost" + total_flight_checked_bags_cost);


    var total_flight_cost = total_traveler_flight_cost + total_amenities +
                            total_flight_checked_bags_cost - flight_discount +
                            total_payrate_cost;
    console.log("total_flight_cost" + total_flight_cost);


    return total_flight_cost;
}

3 个答案:

答案 0 :(得分:3)

var flight_amenities = Number(addCheckboxValues("flight_amenities") ||0; 你在(" flight_amenities")之后错过了一个结束括号。

修改

另外,正如fvu所述,at in_flight_amenities = Number(addCheckboxValues("in_flight_amenities")

答案 1 :(得分:2)

简单地说,因为你的许多括号都没有正确关闭。我修好了3个点。

function flightCosts() {

    const cost_per_checked_bag = 50; 
    const typical_flight_speed = 575;
    const hours_in_airport = 5; 

    var traveler_payrate_per_hour = Number(document.getElementById("traveler_payrate_per_hour").value);
    console.log("traveler_payrate_per_hour" + traveler_payrate_per_hour);
    var number_of_travelers = Number(document.getElementById("number_of_travelers").value);
    console.log("number_of_travelers" + number_of_travelers);

    //Flight Costs
    var miles_flying = Number(document.getElementById("miles_flying").value);
    console.log("miles_flying" + miles_flying);
    var flight_cost = Number(document.getElementById("flight_cost").value)
    console.log("flight_cost" + flight_cost);
    var flight_transit_cost = Number(document.getElementById("flight_transit_cost").value);
    console.log("flight_transit_cost" + flight_transit_cost);
    var flight_discount = Number(document.getElementById("flight_discount").value);
    console.log("flight_discount" + flight_discount);
    var flight_amenities = Number(addCheckboxValues("flight_amenities")) ||0;
    console.log("flight_amenities" + flight_amenities);
    var checked_bags_per_traveler = Number(document.getElementById("checked_bags_per_traveler").value);
    console.log("checked_bags_per_traveler" + checked_bags_per_travelers);
    var in_flight_amenities = Number(addCheckboxValues("in_flight_amenities")) ||0;
    console.log("in_flight_amenities" + in_flight_amenities);

    var total_traveler_flight_cost = flight_cost * number_of_travelers;
    console.log("total_traveler_flight_cost" + total_traveler_flight_cost);

    var time_of_flight = miles_flying / typical_flight_speed;
    console.log("time_of_flight" + time_of_flight);

    var total_amenities = (flight_amenities + in_flight_amenities) * number_of_travelers;
    console.log("total_amenities" + total_amenities);

    var total_payrate_cost = (traveler_payrate_per_hour * (time_of_flight * 2) + hours_in_airport) * number_of_travelers;
    console.log("total_payrate_cost" + total_payrate_cost);

    var total_flight_checked_bags_cost = check_bags_per_traveler * cost_per_checked_bag * number_of_travelers;
    console.log("total_flight_checked_bags_cost" + total_flight_checked_bags_cost);


    var total_flight_cost = total_traveler_flight_cost + total_amenities +
                            total_flight_checked_bags_cost - flight_discount +
                            total_payrate_cost;
    console.log("total_flight_cost" + total_flight_cost);


    return total_flight_cost;
}

你会做很多像这样的事情: Number(addCheckboxValues("flight_amenities") ||0;。但是你注意到没有右括号?

然后你有这条线:     var total_payrate_cost = (traveler_payrate_per_hour * (time_of_flight * 2) + hours_in_airport) ) * number_of_travelers;

请注意有一个额外的右括号怎么做?

错误意味着它所说的内容。

答案 2 :(得分:-1)

同样在这一行:

password_verify($pass /** the unhashed one */, $check_user['pass'])

您缺少终止;