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

JavaScript

JavaScript text adventure game question.

Hello, Im currently making a text adventure game, with JavaScript.

And for the user to type in Input and confirm certain things, i use "Prompt" and "Alert" boxes.

And i wonder if there is anyway to make a Text Adventure Game without using these prompt and alert boxes. And if so, how? where is a good place to learn how to do it.

I would like to have like a DIV screen showing the questions and alerts, and then the user types in the answer.

// erdrag

I would suggest using an

<input>

or

<textarea>

Tag for player data entry. You can then also use jquery to grab the info that the player has entered into the input field.

You can maybe check out this tutorial: http://domscode.com/2013/05/07/1160/ for more info on creating a Text Adventure game.

You can also use jQuery to provide feedback to the player

One simple example would be:

if (playerFoundTreasure) {
  $("feedbackDiv").html("You found the treasure!");
}

is there anyway to grab the info from <input> using javascript only? because i have not learned jquery yet.

// erdrag

You could use the contenteditable attribute (contenteditable="true") and add an event listener for a keypress (e.g. enter) in the chosen div.