0

Function

Anyone knows how i can get the year of birth with the argued age? https://code.sololearn.com/WVfn8FX65jdS/?ref=app

26th Dec 2020, 1:37 PM
Lenoname
4 odpowiedzi
+ 5
Couple of simple changes. function person(name,age,height){ this.name=name; this.age=age; this.yearofbirth=yob(this.age); } function yob(age){ return 2020-age; } var x=new person("me",23); console.log(x);
26th Dec 2020, 1:52 PM
Russ
Russ - avatar
+ 4
this.x can only be used in class Try this class person { constructor (name,age){ this.name=name; this.age=age; } yob() { return 2020-this.age; } } var x=new person("me",23); var yr=x.yob(); console.log(yr);
26th Dec 2020, 1:47 PM
Calviղ
Calviղ - avatar
+ 2
Yaser Already described here: https://www.sololearn.com/learn/JavaScript/1154/ You just need to write like this: console.log(x.yearofbirth()) --------+------ function person(name, age) { this.name=name; this.age=age; this.yearofbirth=yob; } function yob(){ return 2020-this.age; } var x=new person("me",23); console.log(x.yearofbirth())
26th Dec 2020, 2:46 PM
A͢J
A͢J - avatar
+ 1
I don't quite understand what you want but if you want an output you can use console log console.log(x.yearofbirth());
26th Dec 2020, 1:43 PM
Abhay
Abhay - avatar