Guest User

Solution to Challenge "Applying a Discount Code"

a guest
Jan 3rd, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. // You check if the char is not a letter OR not the $ symbol, you should be checking if it is not a letter AND not the $ symbol.
  2.  
  3. // In other words change the || (OR) operator to && (AND) in your if statement like this:
  4.  
  5. private String normalizeDiscountCode(String discountCode){
  6.   for(char c : discountCode.toCharArray()){
  7.     if(!Character.isLetter(c) && c != '$'){
  8.       throw new IllegalArgumentException("Invalid discount code");
  9.     }
  10.   }
  11.   return discountCode.toUpperCase();
  12. }
  13.  
  14. // And you will be able to pass the challenge.
Advertisement
Add Comment
Please, Sign In to add comment