JavaScript DOM Scripting By Example Improving the Application Code Improving the Application Code Review

Seth Pabst
Seth Pabst
5,388 Points

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
159,265 Points

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

Seth Pabst
Seth Pabst
5,388 Points

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); } });

Seth Pabst
Seth Pabst
5,388 Points

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

1 Answer

Steven Parker
Steven Parker
159,265 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.