Bummer! You must be logged in to access this page.

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

Incorrect syntax in quiz question: Java data structures switches: semicolon instead of colon

I submitted this to the support team -- they asked me to post it in the form. My original issue report to them follows:

http://teamtreehouse.com/library/java-data-structures/efficiency/switches

In the question titled 'Fill in the missing blanks in the switch statement below:', the user is presented with three blanks to populate (I've labeled each with a number below). The second blank (labeled below with a '1', as any good developer would expect :)) expects the student to enter 'case', or, at least, is marked as correct when the user does so.

The line in question is terminated with a semicolon but I think the proper syntax is a colon, instead. See http://docs.oracle.com/javase/specs/jls/se7/html/jls-14.html#jls-14.11.

Thanks for adding Java courses!

Fill in the missing blanks in the switch statement below:

String response = console.readLine("Do you understand the switch statement?";
switch(response) {
  case "yep":
    System.out.println("Awesome!  Good job");
   break;
  case "kind of":
    System.out.println("Does this link help?  http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html");
0   _______ ;
1  _______ "nope";
     System.out.println("It is really just a replacement for if else statements.");
     break;
2 _______ :
     System.out.println("We didn't find what you entered.  This is the default answer");
}

3 Answers

I believe the answer should be as follows:

  1. break
  2. case
  3. default

"default" is used to capture anything that didn't hit one of the case statements. It is part of the syntax of the switch statement.

I was able to get through the exercises without trouble, but what I was reporting was what I believe to be a syntax error in the provided code. The error being that the question is using the wrong syntax for a case statement. I strongly encourage everyone to have a look at the question, uhhh, in question because I'm clearly not doing a good job of explaining what I saw :).

This question is a fill-in-the-blank, so there are no compilation issues with which to have problems. Which is why I felt it was more appropriate to email support (as I would with a spelling error) than to post to the forums initially.

What I'm seeing is that the break statement as written in the question would end up looking something like this:

String response = console.readLine("Do you understand the switch statement?";
switch(response) {
  case "yep":
    System.out.println("Awesome!  Good job");
    break;
  case "kind of":
    System.out.println("Does this link help?  http://docs.oracle.com/javase/tutorial/java/nutsandbolts/switch.html");
    break;
  case "nope";
    System.out.println("It is really just a replacement for if else statements.");
    break;
  default:
    System.out.println("We didn't find what you entered.  This is the default answer");
}

My original report was "I think that there should be a colon -- not a semi-colon -- after "nope".

Again, this is more of a non-consequential spelling-ish error since, because of the type of question this is, it doesn't prevent folks from completing the challenge. I thought I'd point out what I believe to be a syntactic error.

Hi Eric,

I did look at the question before I answered and there was a colon after "nope". Maybe they changed it since you asked your question. In any case, you are correct in saying that there should be a colon after "nope".

Thanks, Brian