Elixir Excerism Track - Lesson 4 "Freelancer Rates"

Elixir
Transcript

English (Auto-generated)

Hello. So today we are going to do the fourth exercise in the elixir track um in exorcism and it is the freelancer rates. So today we're gonna be working mostly with floats and integers um and let's go ahead and get started. So this is just some information about all the different floats and stuff. Um I am doing it on my local machine so that I'm able to share my code with you in the player. Um But perfect, here's the instructions. Alright. In this exercise you'll be writing code to help a freelancer communicate with the Project manager by providing a few utilities to quickly calculate daily and monthly rates. Optionally, with a given discount, we first established a few rules between the freelancer and the project manager. The daily rate is eight times the hourly rate A month is 22 billable days. The freelancers offering to apply discount if the project manager chooses to let the freelancer bill per month, which can come in handy if there is a certain budget the project manager has to work with discounts are modeled as fractional numbers representing percentage, for example, 25.0. Alright, that is very confusing. So let's take it one step at a time. The freelancers offering to apply discount. The project manager chooses to let the freelancer bill per month, so they can take a discount if they do it monthly. Okay, so for the first one here implement a function to calculate the daily rate given an hourly rate. Daily rate is eight times the hourly rate, of course, because it's eight hours um the returned daily rate should be afloat. So here we can do hourly rate Times eight but we'll do 8.0 because a few times it was a float it will always come back as a float. So let's go ahead and test that one. And those three paths so perfect, we'll move on to the next one. Supply discount, implement a function to calculate the price after a discount. The return value should always be afloat not rounded in any way. Alright so what we want so we have four discount, just get rid of these comments here make it a little nicer looking. So we will do okay to calculate the discount. We're gonna do, We want to divide the discount by 100 and then subtract it from where's my calculator? Make sure my math makes sense here Math is not Okay. So if we were dividing It's just kind of 25, Let's say we just got 25%. Um we would want to subtract that, I actually want to do it, we want to reverse it. So typically what we could do, if we did 25 invited by 100 we would have just a discount but we actually want to make it one step easier. So we want to remove it from 100. So we're left with the total amount That's had the discounted amount removed. Does that make sense? So we want to have .75. So we should be able to do 100 minus 25 divided by. And that way when we times that by whatever our actual amount is, Times .75 We'll get the amount with the discount applied. Perfect. So Let's do before discount and we're going to be multiplying it against the discount. So we're gonna do 100- discount Provided by 100. So again, taking away the discount. So like let's say it's 25 to 25 ft from 100 and 75 divided by, this would be 750.75. So we're taking 0.75 of the original price and that is the 25% discount applied. Perfect. So let's give that a shot mm hmm. Perfect. So all those ones worked. Alright. So monthly rates here implement a function to calculate the monthly rate and apply a discount. The return monthly rate should be rounded up, take the ceiling to the nearest integer. Okay. So we want our monthly rate too. We know we have 22 days. That's what I said right 2022 billable days in a month. So let's say our monthly is we need to get our daily rate that only gives us an hourly here. So our early raped Times 22. And then we want to apply the discount to that. So we'll say apply discount and we'll pass it that original monthly amount and then whatever the discount is, everything is hard. Um but we need to round it to round up, take the ceiling to the nearest integer. Okay so if we look at elixir um float steel function will round up to um include, my brain is not working to include um decimals. So we're gonna need to round it up and to um use the trunk function to trim it down, explain the trunk function in the rules here. Um It says you can use the trunk um to describe the decimal part. So let's just do this and then we will give it float steel and then we will use and perfect. All of our monthly rate ones have passed and now we're gonna do our days in the budget. So for our compensation I'm just gonna compensation let's determine what are compensation is days in the budget, wait include a function that takes a budget an hourly rate on a discount and can like how many days of work that covers? Yeah. Okay so days in the budget return number of days should be rounded down to one decimal place. Okay so our compensation is going to be our daily rate minus or with the discount right? That's what it said in a discount. And how many days of work that covers? Okay so we're gonna say that we're going to have our daily rate, I'm taking the hourly rate again and then we're going to apply the discount to it, it's passing this along so we're just gonna add the discount variable. Um and then what we're gonna do is we're going to divide the budget by compensation, I'm choosing conversation because that's the word. That makes sense to me here, you can call it whatever you want. Of course it's just a variable but I mean it's like it's the way it's just it's the compensation for the workers. So um that will provide the amount but we need to round it down, take the floor to one decimal place. So let's go back to our docs here and look at the floor so we can put in how many the precision range. So we should be able to do float. Uh four and then one. Mhm. Perfect. So I hope that makes sense. Um We are taking, I'm just gonna go over everything again so the daily rate, we're just taking the hourly rate, multiplying it by eight but we're keeping, we're making it a float so that it returns a float for the applying the discount we're taking the discount and we're giving We're kind of flipping it. So if the 25% discount we're going to be returning um the amount of the discount removed already. So We're gonna do everything out of 100 of course to make it that decimal. So if we're gonna be removing 25% will be multiplying it 5.75 so that we just get the amount. So we're going to take that amount of the discount there and apply the discount which will return it there and we're not doing any kind of um changes to it as far as decimals around it or anything like that Um for the monthly rate, we are taking the daily rate and multiplying it by 22, which is the amount of billable days in a month. Then we are going to apply the discount um you know, we can actually, I think we can actually just do all of this with that is nice looking but just make it a little yes, yeah, so we can do it all without using variables there, we could do the same thing, I'm gonna leave this one as it is because it's a little more complicated but yeah, so we're gonna take the daily rate Multiplied by 22. So we get our monthly rate here that we're gonna apply the discount and then we're going to round it up and turn it into an integer for days in the budget, we're going to find out our general compensation of a worker by taking the daily rate and applying the discount and then we're going to be looking at the budget divided by the daily amount that the worker will make. So the compensation for the day, I should probably call it daily compensation so that it makes more sense. And then we are rounding it down to the nearest one decimal. So I hope that helps with the freelancer rates and I will see you soon for more exercises.
409 Views 0 Likes 0 Comments

Let's tackle the fourth lesson in the Elixir track, which works with floats and integers.

Comment
Leave a comment (supports markdown format)