fork download
  1.  
  2. function Gamburger(size, stuff, spiсes, mayo) {
  3. var SIZE = {
  4. small: {
  5. cost: 50,
  6. cal: 20
  7. },
  8. big: {
  9. cost: 100,
  10. cal: 40
  11. }
  12. };
  13.  
  14. var STUFF = {
  15. cheese: {
  16. cost: 10,
  17. cal: 20
  18. },
  19. salad: {
  20. cost: 20,
  21. cal: 5
  22. },
  23. potato: {
  24. cost: 15,
  25. cal: 10
  26. }
  27. };
  28.  
  29. var SPICES = {
  30. cost: 15,
  31. cal: 0
  32. };
  33.  
  34. var MAYO = {
  35. cost: 20,
  36. cal: 5
  37. };
  38.  
  39. var size = size.toLowerCase();
  40. var stuff = stuff.toLowerCase();
  41. //var spiсes = spiсes || undefined;
  42. //var mayo = mayo || undefined;
  43.  
  44. function calc(value) { //calculate total cost OR total cals
  45. if (!checkValues()) return;
  46. var result = SIZE[size][value] + STUFF[stuff][value];
  47. if (spiсes) result += SPICES[value];
  48. if (mayo) result += MAYO[value];
  49. return result;
  50. }
  51.  
  52. function checkValues() { //checking of arguments
  53. var checked = true;
  54. if (!(size in SIZE)) {
  55. console.log('Нет такого размера!');
  56. checked = false;
  57. }
  58. if (!(stuff in STUFF)) {
  59. console.log('Нет такой начинки!');
  60. checked = false;
  61. }
  62. return checked;
  63. }
  64.  
  65. this.getCost = function() {
  66. return calc('cost');
  67. }
  68.  
  69. this.getCals = function() {
  70. return calc('cal');
  71. }
  72.  
  73. }
  74.  
  75. var gamburger = new Gamburger('Small', 'salad', false, true);
  76. console.log(gamburger.getCost() + " " + gamburger.getCals());
  77.  
Runtime error #stdin #stdout #stderr 0.01s 30272KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
prog.js:76:2 ReferenceError: console is not defined