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 Java Basics Perfecting the Prototype Reviewing Our Feedback

Gurleen Singh
Gurleen Singh
1,452 Points

Wrong line of execution: The new 'int' and 'if' statements aren't being executed yet the previous code is.

The new new code:

        int age = 12;
        if (age < 13) {
           console.printf("Sorry you must be at least 13 to use this program.\n");
           System.exit(0);
           }

is not being executed at all and I don't know why.

The previous code:

        String name = console.readLine("Enter a name:  ");
        String adjective = console.readLine("Enter an adjective:  ");
        String noun = console.readLine("Enter a noun:  ");
        String adverb = console.readLine("Enter an adverb:  ");
        String verb = console.readLine("Enter a verb ending with -ing:  ");

        console.printf("Your TreeStory:\n------------\n");
        console.printf("%s is a %s %s. ", name, adjective, noun);
        console.printf("They are always %s %s.\n", adverb, verb);

seems to be working fine

https://w.trhou.se/eexmpbxftl

2 Answers

Gurleen Singh
Gurleen Singh
1,452 Points

The problem was with the browser and not the code. The code works fine when I tried on a different browser. Thanks for your help nevertheless.

That code is highly unlikely to be browser specific. How are you running this? How is the browser relevant?

Gurleen Singh
Gurleen Singh
1,452 Points

I was running it on Chrome, on which it just wouldn't execute any new code (not just the one shown above). I tried it on Safari and it worked fine. Tried it on Chrome again today and it also seems to be working fine. I don't understand it either by any additional code to this would not be detected (after saving it etc.):

    String name = console.readLine("Enter a name:  ");
    String adjective = console.readLine("Enter an adjective:  ");
    String noun = console.readLine("Enter a noun:  ");
    String adverb = console.readLine("Enter an adverb:  ");
    String verb = console.readLine("Enter a verb ending with -ing:  ");

    console.printf("Your TreeStory:\n------------\n");
    console.printf("%s is a %s %s. ", name, adjective, noun);
    console.printf("They are always %s %s.\n", adverb, verb);

It works for me ... the program exits with the string output of "you must be at least 13".

Steve.