2017-05-05 134 views
-4

我需要,建立一个家谱。我将为祖父母创建一个包含以下属性的类:头发颜色,眼睛颜色和垂直。头发颜色和眼睛颜色可以是字符串,但是垂直应该是一种显示人可以在控制台中跳跃的程度的方法。我必须将父母和孩子纳入代码,我该怎么做?刚刚学习javascript

'use strict' 
class user{ 
    constructor(hairColor, eyeColor, vertical){ 
     this.hairColor = hairColor; 
     this.eyeColor = eyeColor; 
     this.vertical = vertical; 
    } 

    register(){ 
     console.log(+'Grandma can jump'+this.vertical+'inches'+); 
    } 

} 
let grandma = new user ('white', 'blue', 10); 
grandma.register();  
+4

在提出新问题前,请先阅读https://stackoverflow.com/help/how-to-ask –

回答

1

欢迎来到SO,先来看看this

否则您的代码在注册方法()中有错误。

console.log('Grandma can jump'+this.vertical+'inches'); //remove first and last + 
+2

最后一个'+'可能并不是必需的。 – bmceldowney

+0

是错过了!谢谢! –