javascript中的原型函数返回NaN

时间:2018-05-23 12:37:28

标签: javascript return prototype nan

我在这里有这个代码由于某种原因返回NaN,但是当我console.log部分返回时它返回一个实际数字。我试过Math.floor, parseInt`,我不知道该怎么办......

nouveauVoyage.prototype.prixGlobalParPersonne = function(){
    var frais=0;
    if (this.voiturePlaces == 0 && this.hotelPlaces == 0){
        frais=0;
    }else if(this.voiturePlaces != 0 && this.hotelPlaces != 0){
        frais=40;
    }else if((this.voiturePlaces != 0 && this.hotelPlaces == 0) || (this.voiturePlaces == 0 && this.hotelPlaces != 0)){
        frais=20;
    }
    return ((this.nbrAdultes * this.prixParPersonne) + ((this.prixParPersonne * this.nbEnfants) * 0,8) + frais) / (this.nbAdultes + this.nbEnfants);
};

有关详细信息,请参阅我的构造函数

function nouveauVoyage(type,destination,nbrAdultes,nbrEnfants,prixParPersonne,prixParGroupe,placesVoitures,placesHotel){
        this.id = (new Date().valueOf() + " ").substring(6, 13);
        this.type = type;
        this.destination = destination;
        this.nbrAdultes = parseInt(nbrAdultes);
        this.nbrEnfants = parseInt(nbrEnfants);
        this.prixParPersonne = parseInt(prixParPersonne);
        this.prixParGroupe = parseInt(prixParGroupe);
        this.voiturePlaces = parseInt(placesVoitures);
        this.hotelPlaces = parseInt(placesHotel);
    }

以及我传递给它的内容

var type = $("select").first().val();
var destination = $("input:radio:checked").val();
var nbAdultes = $("input[type=number]").eq(1).val();
var nbEnfants = $("input[type=number]").eq(2).val();
var prixParPersonne = $("input[type=text]").first().val();
var prixParGroupe = $("input[type=text]").last().val()
prixParPersonne = prixParPersonne.substring(0, prixParPersonne.length-1);
prixParGroupe = prixParGroupe.substring(0, prixParGroupe.length-1);
var placesVoiture = $("input[type=number").eq(-2).val();
var placesHotel = $("input[type=number]").last().val();
var voyage = new nouveauVoyage(type,destination,nbAdultes,nbEnfants,prixParPersonne,prixParGroupe,placesVoiture,placesHotel);

0 个答案:

没有答案
相关问题