local cars = {}
function cars.calculate_working_cars_per_hour(cars_per_hour, success_rate)
return cars_per_hour * (success_rate/100)
end
function cars.calculate_working_cars_per_minute(cars_per_hour, success_rate)
return cars.calculate_working_cars_per_hour // 60
end
function cars.calculate_cost(number_of_cars)
if number_of_cars >= 10 then
local group = number_of_cars // 10
local regular = number_of_cars - (group*10)
return (group * 95.000) + (regular * 10.000)
else
return number_of_cars * 10.000
end
end
return cars
#Lua - Cars Assembly Exercise
14 messages · Page 1 of 1 (latest)
Increase your chance of getting help and look like a pro by sharing codeblocks not images. For example, you can type the following. Note, the ``` must be on their own line.
```
for number in range(10):
total += number;
```
Discord will render that as so:
for number in range(10):
total += number;
Click here to learn more about codeblocks: https://exercism.org/docs/community/being-a-good-community-member/writing-support-requests and http://bit.ly/howto-ask
it gives me 2 errors
CODE RUN
assert.are.equal(0.0, cars_assemble.calculate_working_cars_per_hour(0, 100))
assert.are.equal(221.0, cars_assemble.calculate_working_cars_per_hour(221, 100))
assert.are.equal(340.8, cars_assemble.calculate_working_cars_per_hour(426, 80))
assert.are.equal(1398.92, cars_assemble.calculate_working_cars_per_hour(6824, 20.5))
assert.are.equal(0.0, cars_assemble.calculate_working_cars_per_hour(8000, 0))
TEST FAILURE
Expected objects to be equal.
Passed in:
(number) 0
Expected:
(number) 340.80000000000001137
update: fixed the third function error, i put a dot on 95.000 and 10.000 when i should've not, my bad.
still cant understand the first, since its such a straight forward task but idk i might be wrong
apparently in the first function, if you use () to get the rate, it gives a slightly different value at the end so i had to remove em
dont understand why lol
but it works now
Because floats are approximate
And I'm guessing 80 / 100 isn't giving what you expect it to give
You're welcome