Вывод изображения через класс
Ошибка при нажатие на кнопку и data is not defined.
class Tovar{
kol=0;
constructor(name, price, kol){
this.name=name;
this.price=price;
this.kol=kol;
}
getSum(){
let sum=this.price*this.kol
return sum
}
toString(){
return `Название: ${this.name} Цена: ${this.price} Колличество: ${this.kol} Сумма:${this.getSum()}`;
}
inf(){
let nds=this.price-((this.price*20)/100);
return `Цена: ${this.price} С учётом НДС: ${nds}`
}
showImg(){
var img = document.getElementById('someimage');
if (img.style.visibility === 'hidden') {
img.style.visibility = "visible";
}
}
}
let tovar= new Tovar("товар1",100,2)
console.log(tovar.toString())
console.log(tovar.inf())
class Tort extends Tovar{
static producer;
data=new Date(2019, 0, 1).toLocaleDateString();
constructor( ves, kal, srok,name, price, kol,data,city, producer){
super(name, price, kol);
this.ves=ves;
this.kal=kal;
this.data=data;
this.srok=srok;
this.city=city;
this.producer=producer;
}
getDataDo(){
data.setDate(data + 7);
let dataDo=this.data+this.srok;
return dataDo
}
toString(){
return `Название: ${this.name} Цена: ${this.price} Колличество: ${this.kol} Срок годности:${this.getDataDo()} вес: ${this.ves} Калории: ${this.kal} Производитель: ${this.producer} Город: ${this.city} `;
}
}
let tort=new Tort(100,500,5,"товар2",150,1,"Некто","Москва")
console.log(tort.toString())
<div>
<div>
<button onclick="showImg();">Показать изображение</button>
<img src="img/images1.jpg" id="someimage">
</div>
</div>