The script needs to be improved.
The first thing to do is add the deleteParagraph
function as a handler for the button click.
After the first activation of the function, this handler must be removed.
Modify an existing script.
This task is part of the Full-Stack JavaScript Course
If you have any issues with it, you can ask for community help below the post
Feel free to help others if you’ve already solved the task
index.html
<!DOCTYPE html>
<html>
<head>
<title>Remove</title>
</head>
<body>
<p>Paragraph 1</p>
<p>Paragraph 2</p>
<button>Delete paragraph</button>
<script>
const button = document.querySelector('button');
function deleteParagraph() {
const paragraphs = document.querySelectorAll('p');
paragraphs[paragraphs.length - 1].remove();
}
</script>
</body>
</html>