Advertisement
makispaiktis

7. Codecademy Intro - Meal Maker

Oct 21st, 2024
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. menu = {
  2.     _meal: '',
  3.     _price:0,
  4.     set meal(mealToCheck){
  5.         if(typeof mealToCheck === 'string'){
  6.             this._meal = mealToCheck;
  7.         }
  8.         else{
  9.             console.log('Tried to create a meal that is not of string data type');
  10.         }
  11.     },
  12.     set price(priceToCheck){
  13.         if(typeof priceToCheck === 'number'){
  14.             this._price = priceToCheck;
  15.         }
  16.         else{
  17.             console.log('Tried to create a price that is not of number data type');
  18.         }
  19.     },
  20.     get todaysSpecial(){
  21.         // Default values (without setters) are falsy
  22.         if(this._meal && this._price){
  23.             return `Today’s Special is ${this._meal} for $${this._price}!`;
  24.         }
  25.         else{
  26.             return 'Meal or price was not set correctly!';
  27.         }
  28.     },
  29.     clear(){
  30.         this._meal = '';
  31.         this._price = 0;
  32.     }
  33. }
  34.  
  35. menu.meal ='Pasta';
  36. menu.price = 10;
  37. console.log(menu.todaysSpecial);
  38. menu.clear();
  39.  
  40. console.log();
  41. menu.meal ='Fish';
  42. menu.price = 'Expensive';
  43. console.log(menu.todaysSpecial);
  44.  
  45.  
  46.  
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement