Created
January 5, 2021 14:47
-
-
Save Haumer/7b135e414cf86ed0dc03773dcf29b0ba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 02-Flow-Array/01-Can-you-vote/ | |
| def allowed_to_vote?(age) | |
| # TODO: return (not print!) a boolean stating whether `age` is old enough to vote | |
| # NOTE: Use an if/else statment | |
| unless age > 18 | |
| puts false | |
| else | |
| puts true | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 04-Hash-Symbols/01-Modeling-with-Hash | |
| DISHES_CALORIES = { | |
| "Hamburger" => 250, | |
| "Cheese Burger" => 300, | |
| "Big Mac" => 540, | |
| "McChicken" => 350, | |
| "French fries" => 230, | |
| "Salad" => 15, | |
| "Coco Cola" => 150, | |
| "Sprite" => 150 | |
| } | |
| def poor_calories_counter(burger, side, beverage) | |
| # TODO: return number of calories for this mcDonald order | |
| dishes_calories[burger] + dishes_calories[side] + dishes_calories[beverage] | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 04-Hash-Symbols/02-Modeling-with-Hash | |
| DISHES_CALORIES = { | |
| "Hamburger" => 250, | |
| "Cheese Burger" => 300, | |
| "Big Mac" => 540, | |
| "McChicken" => 350, | |
| "French Fries" => 230, | |
| "Salad" => 15, | |
| "Coca Cola" => 150, | |
| "Sprite" => 150 | |
| } | |
| MEALS = { | |
| "Happy Meal" => ["Cheese Burger", "French Fries", "Coca Cola"], | |
| "Best Of Big Mac" => ["Big Mac", "French Fries", "Coca Cola"], | |
| "Best Of Royal Cheese" => ["McChicken", "Salad", "Sprite"] | |
| } | |
| def poor_calories_counter(burger, side, beverage) | |
| DISHES_CALORIES[burger] + DISHES_CALORIES[side] + DISHES_CALORIES[beverage] | |
| end | |
| def calories_counter(orders) | |
| total = 0 | |
| orders.each do |order| | |
| if DISHES_CALORIES.key?(orders) | |
| total += DISHES_CALORIES[order] | |
| else | |
| total += poor_calories_counter(DISHES_CALORIES[order].first, DISHES_CALORIES[order].second, DISHES_CALORIES[order].third) | |
| end | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # 03-Iterators-Blocks/04-HTML-generator/ | |
| def tag(tag_name, attributes = nil) | |
| # TODO: Build HTML tags around content given in the block | |
| # The method can be called with an optional HTML attribute inputted as [attr_name, attr_value] | |
| if attributes.nil? | |
| "<#{tag_name}#{yield}</#{tag_name} >" | |
| else | |
| "<#{"#{tag_name} #{attributes.last}="#{attributes.first}""} >#{yield}</#{tag_name} >" | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment