Help with modifying variables during order of operations

Hi,
I’m following along examples in a book and I’m getting an error which doesn’t make sense because when I try the suggested solution in the help, I get the same error.

Thank you,
Leo

defmodule Checkout do
  def total_cost(price, tax_rate) when price >= 0 and tax_rate >= 0 do
    tax_rate = tax_rate +1
    price * tax_rate
  end
end

iex(2)> c "test.ex"

== Compilation error in file test.ex ==
** (CompileError) test.ex:8: "tax_rate +1" looks like a function call but there is a variable named "tax_rate".
If you want to perform a function call, use parentheses:

    tax_rate(+1)

If you want to perform an operation on the variable tax_rate, use even spaces instead:

    tax_rate + 1

** (CompileError)  compile error
    (iex 1.10.2) lib/iex/helpers.ex:200: IEx.Helpers.c/2

The same error when I try:

defmodule Checkout do
  def total_cost(price, tax_rate) when price >= 0 and tax_rate >= 0 do
    price * tax_rate +1
  end
end

Your issue is simply the lack of space between + and 1. The error message says what to do:

If you want to perform an operation on the variable tax_rate, use even spaces instead:

    tax_rate + 1
2 Likes

Thank you so much! N00b mistake

3 Likes