Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javascript中的原型函数返回NaN_Javascript_Return_Prototype_Nan - Fatal编程技术网

javascript中的原型函数返回NaN

javascript中的原型函数返回NaN,javascript,return,prototype,nan,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;

我这里有一段代码,出于某种原因返回
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(因此this.nbAdultes+this.nbEnfants==0?),但你可能是指
0.8
,不是。我更改了它,但它没有消除问题:/,也许是我真的不知道的除法,可能是因为你在除以(nbEnfants和nbAdultes)不适用于新生代。请在功能PrixGlobalParpersone内将所有nbEnfants更改为nbrEnfants,并将所有nbAdultes更改为nbAdultes