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

Java

Carlos Mota
Carlos Mota
2,596 Points

DiscountCode question for Java course

I'm on the problem where you need to normalize discountCode and my method seems to work fine outside of the treehouse test environment, but it does not seem to be working in it any help greatly appreciated.

Carlos Mota
Carlos Mota
2,596 Points
private String normalizeDiscountCode(String discountCode){
    if(!discountCode.contains("$") || discountCode.matches("[a-zA-Z]")){
      throw new IllegalArgumentException("Invalid discount code");
    }
    return discountCode = discountCode.toUpperCase();
  }
Jason Anders
Jason Anders
Treehouse Moderator 145,860 Points

Hi Carlos,

If you could post the link to the challenge you are working on, or even better, click the Get Help button from the actual challenge. This way the correct challenge link, and all relevant instructions and code are include in the Post (make sure the "include my code" box is checked.
It's really tough to assist in trouble shooting when all the information is not here, as challenges are very specific, so it could be something as simple as a misplaced period or a typo.

But just looking at your code snippet, you can't assign a value in a return statement. Are you meaning to check a comparison and return a Boolean? Single = is an assignment operator. Double == is a comparison operator. ??

This will help the Community provide a quick assist. :) :dizzy: