Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Go Language Go Language Overview Go Syntax Functions

Antoine Solomon
Antoine Solomon
2,850 Points

I seem to get an error when running one of the go challenges

Ok so where's the question. I believe my code is working but I get an error.

challenge:

In the sales package, define an exported CalculateTax function. CalculateTax should accept a float64 parameter representing a sales total, and a second float64 parameter representing a tax rate. The function should multiply the sales total by the tax rate, and return the result as a float64 value. So, for example, sales.CalculateTax(100.0, 0.08) should return approximately 8.0. (Very small floating-point math errors are OK.)

Error: Bummer! # command-line-arguments ./report.go:9: multiple-value sales.CalculateTax() in single-value context

My code description:
The error appears on "func CalculateTax(salesTotal, taxRate float64) (float64, error) {"

package sales

import ( "fmt" )

func CalculateTax(salesTotal, taxRate float64) (float64, error) { result := salesTotal * taxRate // Check the value if result <= 0 { return result, fmt.Errorf("Please check your sales total %f and tax rate %f", salesTotal, taxRate) } return result, nil }

Now I believe the treehouse code check won't accept parameters since the error string calls sales.CalculateTax(). Not a 100% sure but wanted to check with you all.

src/code.my.com/git/sales/tax.go
package sales

import (
  "fmt"
 )

func CalculateTax(salesTotal, taxRate float64) (float64, error) {
  result := salesTotal * taxRate
  // Check the value 
  if result <= 0 {
    return result, fmt.Errorf("Please check your sales total %f and tax rate %f", salesTotal, taxRate)
  }
  return result, nil
}
Antoine Solomon
Antoine Solomon
2,850 Points

I actually got this working

func CalculateTax(salesTotal, taxRate float64) (result float64) {
  result = salesTotal * taxRate
  return result
}

1 Answer

Steven Parker
Steven Parker
229,732 Points

You got a bit too fancy. The challenge was looking specifically for the function to take two arguments and return one. Adding in the error return was confusing the check mechanism.

Antoine Solomon
Antoine Solomon
2,850 Points

Very true. Hoping for a golang track in the future.