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 DOM Scripting By Example Improving the Application Code Improving the Application Code Review

need help with workspace project

so I just finished the rsvp app in this course. in this latest video the instructor finishes refractoring and throws a few ideas out for how to further improve the app. He mentions how when the input is empty and submitted a blank list item is appended. I tried the method he suggested, which was to check if it was blank then break from the handler. Well I tried that with ----> if ( text === ' ' ) { break; }

this broke my app, and wont even let me submit a name. I but this bit of code in multiple places in my handler for the form, but it breaks???? why is this, and is that code even correct??

Steven Parker
Steven Parker
230,248 Points

If you show your code or provide a snapshot link, someone might be able to help spot the issue.

hers the code block ---->

form.addEventListener('submit', (e) => { if (text === '') { break; } else { e.preventDefault();
const text = input.value; input.value = ''; const li = createLi(text); ul.appendChild(li); } });

if you take the if else statement out, the code runs fun but not with it.

1 Answer

Steven Parker
Steven Parker
230,248 Points

A workplace snapshot would provide a complete environment to replicate and analyze the issue.

But one thing stands out in this snippet that might be the whole problem: it includes a "break" statement. A "break" without a label is only allowed inside a loop or switch, but there's neither of those in this code.