exercism/elixir/remote-control-car/HINTS.md

2.0 KiB

Hints

General

1. Create a brand-new remote controlled car

  • The module attribute @enforce_keys can be used to specify required values. It needs to be defined before calling defstruct.
  • The nickname field should not have a default value specified.
  • The new/0 function should initialize the nickname with the value "none".

2. Create a brand-new remote controlled car with a nickname

3. Display the distance

  • For functions which accept only a specific type of struct, make sure you perform a pattern match to check the argument.
  • Use the static access operator to obtain field values.

4. Display the battery percentage

  • For functions which accept only a specific type of struct, make sure you perform a pattern match to check the argument.
  • Use the static access operator to obtain field values.

5. Driving changes the battery and distance driven

  • For functions which accept only a specific type of struct, make sure you perform a pattern match to check the argument.
  • Use the static access operator to obtain field values.
  • Review the introduction for updating structs.

6. Account for driving with a dead battery

  • If the battery is dead, it should return the struct unchanged.