JavaScript DOM Scripting By Example Improving the Application Code Next Steps

Siddharth Pandey
Siddharth Pandey
4,069 Points

Why doesn't this work???

I tried adding an alert when the list item's text content is blank, but it's not appearing for some reason.

Here is the link to a snapshot of my code:

https://w.trhou.se/sqeu62i89d

This line in particular:

    if (span.text == '') {
      alert('The guest you have added has no name');
    }

I have also tried span.textContent but it still doesn't work.

Why is this, and how can I fix it, I would really appreciate any help.

1 Answer

KRIS NIKOLAISEN
PRO
KRIS NIKOLAISEN
Pro Student 49,649 Points

I switched index.html to

<script src="myscript.js"></script>

where that code is located and in the console found

myscript.js:80 Uncaught ReferenceError: span is not defined
    at HTMLUListElement.<anonymous> (myscript.js:80)

which it isn't.

Siddharth Pandey
Siddharth Pandey
4,069 Points

What do you mean by "which it isn't," and how can I fix this.