JavaScript DOM Scripting By Example Improving the Application Code Next Steps

Siddharth Pandey
Siddharth Pandey
6,846 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:

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

54,335 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
6,846 Points

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