MadLibs Coding Help

I keep getting an error with MadLibs Project…Can someone offer advice on my code?

public class MadLibs {
  /*This program generates a mad libbed story. 
   Author: Laura Date: 2/19/2049
  */
  	public static void main(String[] args){
      
      
      
    System.out.println(story);"This morning "+name1+" woke up feeling "+adjective1+". 'It is going to be a "+adjective2+" day!' Outside, a bunch of "+noun1+"s were protesting to keep "+noun2+" in stores. They began to "+verb1+" to the rhythm of the "+noun3+", which made all the "+noun4+"s very "+adjective3+". Concerned, "+name1+" texted "+name2+", who flew "+name1+" to "+place1+" and dropped "+name1+" in a puddle of frozen "+noun5+". "+name1+" woke up in the year "+number+", in a world where "+noun6+"s ruled the world.";
    }       
}

Link to project: https://www.codecademy.com/courses/learn-java/projects/java-variables-mad-libs

Hello, @kwillrun. Welcome to the forums.

The code you posted looks like the original skeleton code provided by the exercise with only your comment added. What error are you getting? Also, please review How do I format code in my posts? Following the guidelines there will keep the forum markdown from messing with your original code formatting. I edited your post, so you can see the difference. It’s also a good idea to include a link to the project or exercise when asking a question regarding Codecademy content.

Having looked at the project, and seeing your code, you have not followed the instructions. I’d suggest clicking the reset button, and starting again following each instruction carefully in order. Currently, you’re code is asking the computer to print a variable named story, but your code doesn’t define a variable named story. The long concatenated string following System.out.println(story); is the value that was originally assigned to story before you changed it. If you follow the instructions carefully, you’ll define each variable used in the value assigned to story (ie. name1, adjective1, etc.).

Hi…thanks for your reply. I must have pressed send or closed my compute because I did not intend to send the code that you originally received. Below is my code. I will also review the thread on how to format postings.

public class MadLibs {

/* This program generates a mad libbed story.

Author: Keesha Willingham

Date March 3, 2020 */

public static void main(String args){

String name1 = “Maxwell”;

String adjective1 = “mad”;

String adjective2 = “angrily”;

Sting adjective3 = “loudly”;

String verb1 = “running”;

String noun1 = “book”;

String noun2 = “car”;

String noun3 = “cake”;

String noun4 = “dentist”;

String noun5 = “Naruto”;

String noun6 = “camp”;

int number = 2047;

String place1 = “Lake Charles”;

//The template for the story

System.out.println(“story”);

String story = "This morning “+name1+” woke up feeling “+adjective1+”. ‘It is going to be a “+adjective2+” day!’ Outside, a bunch of "+noun1+"s were protesting to keep “+noun2+” in stores. They began to “+verb1+” to the rhythm of the “+noun3+”, which
made all the "+noun4+"s very “+adjective3+”. Concerned, “+name1+” texted “+name2+”, who flew “+name1+” to “+place1+” and dropped “+name1+” in a puddle of frozen “+noun5+”. “+name1+” woke up in the year “+number+”, in a world where "+noun6+“s ruled the world.”;

}

}

When you try to run your code, you should see an error message. I see several issues with your code, but rather than just tell you what to change, try using the error messages to locate the problems, and correct them. The first error message I received when I tried to run your code was: Error: unclosed string literal in reference to the line beginning with String story = ... It looks as though you altered the original string that is assigned to story by clicking <enter> after the word which, so to the compiler, you have a line of code that looks like this:

String story = "This morning "+name1+" woke up feeling "+adjective1+". 'It is going to be a "+adjective2+" day!' Outside, a bunch of "+noun1+"s were protesting to keep "+noun2+" in stores. They began to "+verb1+" to the rhythm of the "+noun3+", which

followed by a line that looks like this:

made all the "+noun4+"s very "+adjective3+". Concerned, "+name1+" texted "+name2+", who flew "+name1+" to "+place1+" and dropped "+name1+" in a puddle of frozen "+noun5+". "+name1+" woke up in the year "+number+", in a world where "+noun6+"s ruled the world.";

That seems to coincide with the error message: Error: unclosed string literal since there is no closing double quote at the end of the first line. Those two lines were originally one long line of code, and should still be.

After correcting that error, see if you can figure out the next errors. If you need help, post your updated code, and include the error message.

1 Like