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 Censoring Words - Using String Equality

Shehan Dissanayake
Shehan Dissanayake
19,119 Points

No errors! But doesn't run!

String noun = console.readLine("Enter a noun: ");

  if(name.equals("dork")){
    console.printf("That language is not allowed.Exiting.\n\n");
    System.exit(0);
  }

This does compile without error but doesn't execute the if condition when i type "dork" as the noun.

Thoughts?

4 Answers

Huzaifa Sajjad Malik
PLUS
Huzaifa Sajjad Malik
Courses Plus Student 10,823 Points
String noun=console.readLine("Enter a Noun :  ");
if(noun.equals("dork"))
{
   console.printf("This kind of lang is not allowed! Exiting \n\n");
   System.exit(0);
}

The problem here is that you were getting the input in name but were checking the name element thats why it was not executing the way you expected

You are giving 2 different var names: noun and name.

Can you please paste the absolutely full code?

you may have forgot to save before running.