fork download
  1. Hamburger.SIZE_BIG_PRICE = 100;
  2. Hamburger.SIZE_BIG_CALORIC = 40;
  3. Hamburger.SIZE_SMALL_PRICE = 50;
  4. Hamburger.SIZE_SMALL_CALORIC = 20;
  5.  
  6. Hamburger.STUFFING_CHEESE_PRICE = 10;
  7. Hamburger.STUFFING_CHEESE_CALORIC = 20;
  8. Hamburger.STUFFING_SALAD_PRICE = 20;
  9. Hamburger.STUFFING_SALAD_CALORIC = 5;
  10. Hamburger.STUFFING_POTATOES_PRICE = 15;
  11. Hamburger.STUFFING_POTATOES_CALORIC = 10;
  12.  
  13. Hamburger.TOPPING_SAUCE_PRICE = 15;
  14. Hamburger.TOPPING_SAUCE_CALORIC = 0;
  15. Hamburger.TOPPING_MAYO_PRICE = 20;
  16. Hamburger.TOPPING_MAYO_CALORIC = 5;
  17.  
  18. function Hamburger(size_price, size_caloric, stuffing_price, stuffing_caloric) {
  19.  
  20. var price = size_price + stuffing_price;
  21. var caloric = size_caloric + stuffing_caloric;
  22.  
  23. this.addTopping = function (topping_price, topping_caloric) {
  24. price += topping_price;
  25. caloric += topping_caloric;
  26. }
  27.  
  28. this.calculateCalories = function () {
  29. return caloric;
  30. }
  31.  
  32. this.calculatePrice = function () {
  33. return price;
  34. }
  35. }
  36.  
  37.  
  38. // маленький гамбургер с начинкой из сыра
  39. var hamburger = new Hamburger(Hamburger.SIZE_SMALL_PRICE, Hamburger.SIZE_SMALL_CALORIC, Hamburger.STUFFING_CHEESE_PRICE, Hamburger.STUFFING_CHEESE_CALORIC);
  40. // добавка из майонеза
  41. hamburger.addTopping(Hamburger.TOPPING_MAYO_PRICE, Hamburger.TOPPING_MAYO_CALORIC);
  42. // спросим сколько там калорий
  43. console.log("Calories: %f", hamburger.calculateCalories());
  44. // сколько стоит
  45. console.log("Price: %f", hamburger.calculatePrice());
  46. // я тут передумал и решил добавить еще приправу
  47. hamburger.addTopping(Hamburger.TOPPING_SAUCE_PRICE, Hamburger.TOPPING_SAUCE_CALORIC);
  48. // А сколько теперь стоит?
  49. console.log("Price with sauce: %f", hamburger.calculatePrice());
Runtime error #stdin #stdout #stderr 0.43s 323136KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
js: uncaught JavaScript runtime exception: ReferenceError: "console" is not defined.