#Lua cars assemble task 1 wrong

18 messages · Page 1 of 1 (latest)

open fox
#

i don't know what to do

prime whale
#

Could you share your code and the test details as text in a codeblock and not as an image? Images are hard to copy paste from, or even hard to read for many people.

open fox
#

ok

#

-- returns the amount of working cars produced by the assembly line every hour
function cars.calculate_working_cars_per_hour(production_rate, success_rate)
  -- calculate_working_cars_per_hour body
  return production_rate * (success_rate / 100)
  
end```
#

cars.calculate_working_cars_per_hour(1547, 90)
--> => 1392.3
Note: the return value should be a float.```
prime whale
#

Is there a test failure you're getting? Can you share that in a codeblock too?

open fox
#
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) 340
Expected:
(number) 340.80000000000001137```
prime whale
#

Are you returning an integer instead of a float?

#
  1. Do you understand what the test is doing?
  2. Do you understand what the test is expecting and why?
  3. Do you understand what your code returns and how it differs?
  4. Do you understand why your code is returning what it returns?
open fox
#

something is wrong with that preveous test failure. heres what it says now : 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) 1398.9199999999998454 Expected: (number) 1398.9200000000000728

prime whale
#

Try doing the multiplication before the division and see if that helps

open fox
#

it worked

#

thank you

prime whale
#

You're welcome