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.