Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

JavaScript

Jquery Basics: setting a value code challenge

couldn't anderstand the perticular question "A prompt dialog will open prompting for someone's full name. Use jQuery to follow the comments in code. First, select the correct input, and then set it's value to the fullName."

my fale answer: ' ' ' //Show Prompt Window and store value var fullName = prompt("What is your full name?");

//Select Input with the id of #fullName fullName = '<p id="fullName">'fullName"</p>" //Insert value in to full name input $("#fullName").val($("#fullName").attr(fullName)); ' ' '

2 Answers

So what this challenge is asking you to do is the following:

  1. Assign the text entered into a dialog prompt to a variable.

  2. Change the value of an input to the value of that variable.

// 1. Create a variable called fullName, and then assign the value of a prompt to it 
var fullName = prompt("What is your full name?");

//2. Select the input with an id of fullName then change the value to fullName
$('#fullName').val(fullName);
Matthias Nörr
Matthias Nörr
8,614 Points

Why do you use single quotation marks?

$('#fullName')

Matthias Nörr, you can use either single or double quotes, it's a matter of preference, aside from when you need to escape similar quotation marks. Where I work, our standard is to always use single quotes when we can, just for the sake of consistency, so because of that I stick with single quotes. I also feel like at least in my personal opinion they are easier to parse visually.

thank you very much!