Error when running JS inline in html… I had a prompt(‘Side name:’) and it said it expected ";" after side and name

  html, javascript

<button class="middiv-btn" onclick="var itemname=prompt('Item Name:'); var node = document.createElement('li');node.appendChild(document.createTextNode(itemname)); document.querySelector('ul').appendChild(node); var ol=document.createElement('ol'); var addtop=document.createElement('button'); addtop.onclick='var itemname=prompt('Side Name:');'; document.querySelector('ol').appendChild(addtop)">Add an item +</button>

This is my code block. The onclick attribute is the problem. I added an attribute to the addtop button element I made. In the onclick attribute, it says I need a semicolon in the string ‘Side Name:’

Source: Ask Javascript Questions

LEAVE A COMMENT