You have been given a new cookbook for your birthday, and you want to find out if the lasagna recipe in it is better than your current favourite cookbook. In this exercise you're going to write some code to help you cook the lasagna from the new cookbook.
Your housemate is still busy at the office, and wants to know what time the lasagna will be ready, so that she can make sure she is back in time.
Create a function to work out what time the lasagna will be ready. To make the code simple and expressive you should use a let expression.
Define the remainingTimeInMinutes function that takes two parameters and has a let expression as its body. The first parameter is the number of layers in the lasagna, and the second parameter is the number of minutes since you starting cooking.
Define expectedMinutesInOven (in the let part of the let expression) to check how many minutes the lasagna should be in the oven. According to the cookbook, the expected oven time in minutes is 40:
expectedMinutesInOven
--> 40Define preparationTimeInMinutes (in the let part of the let expression) that takes the number of layers in the lasagna as a parameter and returns how many minutes it takes to prepare the lasagna, assuming each layer takes 2 minutes to prepare.
preparationTimeInMinutes 3
--> 6Return how many minutes are left until the lasagna is finished (in the in part of the let expression), which is the sum of the preparationTimeInMinutes and the expectedMinutesInOven minus the number of minutes since you starting cooking.
remainingTimeInMinutes 3 10
--> 6 + 40 - 10 = 36You have been given a new cookbook for your birthday, and you want to find out if the lasagna recipe in it is better than your current favourite cookbook. In this exercise you're going to write some code to help you cook the lasagna from the new cookbook.
Your housemate is still busy at the office, and wants to know what time the lasagna will be ready, so that she can make sure she is back in time.
Create a function to work out what time the lasagna will be ready. To make the code simple and expressive you should use a let expression.
Define the remainingTimeInMinutes function that takes two parameters and has a let expression as its body. The first parameter is the number of layers in the lasagna, and the second parameter is the number of minutes since you starting cooking.
Define expectedMinutesInOven (in the let part of the let expression) to check how many minutes the lasagna should be in the oven. According to the cookbook, the expected oven time in minutes is 40:
expectedMinutesInOven
--> 40Define preparationTimeInMinutes (in the let part of the let expression) that takes the number of layers in the lasagna as a parameter and returns how many minutes it takes to prepare the lasagna, assuming each layer takes 2 minutes to prepare.
preparationTimeInMinutes 3
--> 6Return how many minutes are left until the lasagna is finished (in the in part of the let expression), which is the sum of the preparationTimeInMinutes and the expectedMinutesInOven minus the number of minutes since you starting cooking.
remainingTimeInMinutes 3 10
--> 6 + 40 - 10 = 36