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 trialTuan Phan
10,825 Pointsinput.value = ``; //This make empty string instead of the following things in the video.
My problems is if I do exactly in the video, I do not have the same result. Although, I try out some way to solve it.
Here is my code:
const form = document.querySelector(`#registrar`);
const input = form.querySelector(`input`);
form.addEventListener(`submit`, (e) => {
e.preventDefault();
const text = input.value;
//input.value = ``; This is not work for me
const ul = document.querySelector(`#invitedList`);
const li = document.createElement(`li`);
li.textContent = input.value;
ul.appendChild(li);
input.value = ``;
});
As I understand, we need to wait to the value appear on the page, before we can set that input.value to empty again. So I put that
input.value =``;
at the end of code snippet.
And then I have result as same as the video..
***My question is "Is there something wrong with my code?" or "Did I understand wrongly how the input.value =`` work?"
3 Answers
myri
2,493 PointsI noticed the same behaviour! And it makes sense to me, since we set the input.value to ' ', it prints ' '. Both of these solutions fix it but i still wonder how it works that way on the video. Must be some mistake with the vid?
Tuan Phan
10,825 PointsI am pretty sure that no matter which kind of
input.value = ``;
input.value = '';
input.value = "";
I used, it does not affect to the result. At least, in this case.
You should try it out.
Tuan Phan
10,825 PointsI found it out...As const text stores value of input. I only need to call it. So just need to remove this
li.textContent = input.value;
By this
li.textContent = text;
And no need to worry about
input.value =``;
As long as it is located below const text...