Добрый день! Люди, подскажите пожалуйста, есть код который считает стоимость гамбургера в зависимости от того, какие флажки и радиокнопки мы переключаем. И вот с радиокнопками разобрался, в флажках запутался.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<style type="text/css">
img{
width: 150px;
height: 150px;
}
form{
text-align: center;
width: 50%;
margin: 0 auto;
}
</style>
<form name="burger">
<fieldset>
<legend>Select size</legend>
<label>
<img src="small.jpg" alt="">
<input type ="radio" name = "sizeBurger" value="small"/>
</label>
<label>
<img src="large.jpg" alt="">
<input type ="radio" name = "sizeBurger" value="large"/>
</label>
</fieldset>
<fieldset>
<legend>Select stuffing</legend>
<label>
<img src="cheese.jpg" alt="">
<input type ="checkbox" name = "cheese" value="cheese"/>
</label>
<label>
<img src="salad.jpg" alt="">
<input type ="checkbox" name = "salad" value="salad"/>
</label>
<label>
<img src="potato.jpg" alt="">
<input type ="checkbox" name = "potato" value="potato"/>
</label>
</fieldset>
<fieldset>
<legend>Select topping</legend>
<label>
<img src="mayonez.jpg" alt="">
<input type ="checkbox" name = "mayonez" value="mayonez"/>
</label>
<label>
<img src="spice.jpg" alt="">
<input type ="checkbox" name = "spice" value="spice"/>
</label>
</fieldset>
<input type="button" value="ORDER" name="order">
</form>
<h3 id="result"></h3>
<script >
'use string'
var result = document.getElementById('result');
var but = document.forms.burger.elements.order;
var sizeBurger = document.forms.burger.elements.sizeBurger;
var cheese = document.forms.burger.elements.cheese;
var salad = document.forms.burger.elements.salad;
var potato = document.forms.burger.elements.potato;
var mayonez = document.forms.burger.elements.mayonez;
var spice = document.forms.burger.elements.spice;
var stufPrise;
console.log(cheese.value)
// var a = ['salad','cheese','potato']
class Hamburger{
constructor(size, stuffing, topping){
this.size = size;
this.stuffing = stuffing;
this.topping = topping;
}
// static createHamburger(){
// return new Hamburger('small',['salad','cheese','potato'],['mayonez','spice']);
// }
static get SMALLPRISE(){return 50}//цена маленького гамбургера
static get LARGEPRISE(){return 100}//цена большого гамбургера
static get SALADPRISE(){return 20}//цена салата
static get CHEESEPRISE(){return 10}//цена сыра
static get POTATOPRISE(){return 15}//цена картошки
static get MAYONEZPRISE(){return 20}//цена майонеза
static get SPICEPRISE(){return 15}//цена специй
addStuffin(){
var stufPrise = 0;
if(this.stuffing =='salad'){stufPrise+=Hamburger.SALADPRISE;}
if(this.stuffing =='cheese'){stufPrise+=Hamburger.CHEESEPRISE;}
if(this.stuffing =='potato'){stufPrise+=Hamburger.POTATOPRISE;}
return stufPrise;
}
addTopping(){
var topPrise = 0;
if(this.topping =='mayonez'){topPrise+=Hamburger.MAYONEZPRISE;}
if(this.topping =='spice'){topPrise+=Hamburger.SPICEPRISE;}
return topPrise;
}
calculatePrice(){
if(this.size =='small') return Hamburger.SMALLPRISE+this.addStuffin();
if(this.size =='large') return Hamburger.LARGEPRISE+this.addStuffin();
if(this.stuffing =='salad') return Hamburger.SALADPRISE+this.addStuffin();
if(this.stuffing =='cheese') return Hamburger.CHEESEPRISE+this.addStuffin();
if(this.stuffing =='potato') return Hamburger.POTATOPRISE+this.addStuffin();
if(this.topping =='mayonez') return Hamburger.MAYONEZPRISE+this.addTopping();
if(this.topping =='spice') return Hamburger.SPICEPRISE+this.addTopping();
// addToppin();
else return null;
}
}
// let sample = Hamburger.createHamburger();
// console.log(sample.calculatePrice())
but.addEventListener('click',function(){
var burgerNew = new Hamburger(sizeBurger.value);
result.innerHTML = "Burger cost "+burgerNew.calculatePrice()+"$";
console.log(burgerNew.calculatePrice())
})
</script>
</body>
</html>