I am attempting to create two objects, one from each of my classes - a Person object and a Drink object. I then want to invoke the drinking method by passing in a Drink object. However, I am struggling with how to do this. Here is my code, and I can't seem to identify what's causing it to not work.
function Drink(full, alcoholic){
this.alcoholic = alcoholic;
this.full = full;
}
function Person(name, age) {
this.name = name;
this.age = age;
this.drinking = function drinking(Drink) {
if (age >= 18) {
this.Drink.full = false;
} else {
console.log("You cannot drink because of your age.")
this.Drink.full=true;
};
}
}
John = new Person("John",24);
Sam = new Person("Sam",2);
x = new Drink(true,true);
console.log(x)
console.log(John.drinking(x))
console.log(Sam.drinking(x))