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 jQuery Basics (2014) Creating a Mobile Drop Down Menu Setting a value

Setting value code challenge, jquery

I don't even know what this is asking? Can someone please rephrase what this is asking for? I have been trying to figure it out and am just blocked completely.

I know this isn't right, but I'm stumped on what to do at all.

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

//Select Input with the id of #fullName
$("#fullName");
//Insert value in to full name input
$("fullName").val();

2 Answers

jobbol
seal-mask
.a{fill-rule:evenodd;}techdegree
jobbol
Full Stack JavaScript Techdegree Student 17,885 Points

First it's asking you to find the DOM object. We typically save this to a variable so we can access it again.

var $name =  $("#fullName");

Next the val function has two basic forms.

  1. Getting -- Takes the value out. input = $num.val();
  2. Setting -- Changes the value to something else. $num.val(input);

In this example you want to use #2, to set it to the value stored in fullName.

See if you can put it together.

Thanks, this helped me understand how val works. I find the explanations in the jquery api pretty unhelpful at this stage, but maybe it will make more sense as I go along.

Dana Wren
Dana Wren
12,488 Points

I had problems with this one too, probably because the id name and the variable name were the same. It was much more simple than most of the things I was trying.

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

//Select Input with the id of #fullName
$name = $("#fullName");

//Insert value in to full name input
$name.val(fullName);

I never would have got this. I guess I didn't understand the val function after all. Still not sure I do.