0
Function
Anyone knows how i can get the year of birth with the argued age? https://code.sololearn.com/WVfn8FX65jdS/?ref=app
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);
+ 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);
+ 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())
+ 1
I don't quite understand what you want but if you want an output you can use console log
console.log(x.yearofbirth());