2016-05-23 3 views
0

このコードは自分のjavascriptクラス用ですので、それ自体はウェブサイト自体には必須ではありませんが、残念です。だから私は特定の名前とメソッド(名前、型1、型2、高さまたは重さ)を呼び出すと、自分のコードで提供した答えを得るコードを作成しようとしています。私は未定義になっていますが、インストラクターのデモを見るとうまくいきます。プロトタイプオブジェクト/メソッドコード - コスプ​​レで表示されない

私は本当に簡単なものを逃していないことを願っています。どんな助けでも大歓迎です!

var Pokemon = function Pokemon(name , type1 , type2 , height , weight) { 
    this.name = name; 
    this.type1 = type1; 
    this.type2 = type2; 
    this.height = height; 
    this.weight = weight; 
} 

Pokemon.prototype.whichPoke = function whichPoke() { 
    console.log("Hey, I am " + this.name); 
} 
Pokemon.prototype.whichType1 = function whichType1() { 
    console.log("Hey, I am " + this.type1); 
} 
Pokemon.prototype.whichType2 = function whichType2() { 
    console.log ("Hey, I am " + this.type2); 
} 
Pokemon.prototype.whichHeight = function whichHeight() { 
    console.log ("Hey, I am " + this.height + " inches tall"); 
} 
Pokemon.prototype.whichWeight = function whichWeight() { 
    console.log ("Hey, I am " + this.weight + " pounds") 
} 

var Horsea = new Pokemon({ 
    name: "Horsea", 
    type1: "Water", 
    type2: "none", 
    height: "16", 
    weight: "17.6" 
}) 
var Seadra = new Pokemon({ 
    name: "Seadra", 
    type1: "Water", 
    type2: "none", 
    height: "47", 
    weight: "55.1" 
}) 
var Kingdra = new Pokemon({ 
    name: "Kingdra", 
    type1: "Water", 
    type2: "Dragon", 
    Height: "71", 
    Weight: "335.1" 
}) 

答えて

3

var Pokemon = function Pokemon(name , type1 , type2 , height , weight) { 
 
    this.name = name; 
 
    this.type1 = type1; 
 
    this.type2 = type2; 
 
    this.height = height; 
 
    this.weight = weight; 
 
} 
 

 
Pokemon.prototype.whichPoke = function whichPoke() { 
 
    console.log("Hey, I am " + this.name); 
 
} 
 
Pokemon.prototype.whichType1 = function whichType1() { 
 
    console.log("Hey, I am " + this.type1); 
 
} 
 
Pokemon.prototype.whichType2 = function whichType2() { 
 
    console.log ("Hey, I am " + this.type2); 
 
} 
 
Pokemon.prototype.whichHeight = function whichHeight() { 
 
    console.log ("Hey, I am " + this.height + " inches tall"); 
 
} 
 
Pokemon.prototype.whichWeight = function whichWeight() { 
 
    console.log ("Hey, I am " + this.weight + " pounds") 
 
} 
 

 
var Horsea = new Pokemon("Horsea", "Water", "none", "16", "17.6"); 
 
var Seadra = new Pokemon("Seadra", "Water", "none", "47", "55.1"); 
 
var Kingdra = new Pokemon("Kingdra", "Water", "Dragon", "71", "335.1");

+0

あなたはポケモンオブジェクトを作成するために渡されたパラメータ{...}は一つのオブジェクトではなく、5つのデータです。これは、5つのパラメータではなく、1つのパラメータ - 「名前」として認識されます。残りのパラメータtype1、type2、height、weightは未定義です。 – Kelvin

+0

http://tinypic.com/r/sl4rj9/9 ここではこれが私の問題です。特定の情報は得られません。 haha – JHillman

+0

あなたは何をするつもりなのかわからない – Kelvin

関連する問題