Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Typing in what is the the book I have 2 errors coming up. One is with the var i and one is with the push().

Typing in what is the the book I have 2 errors coming up. One is with the var i and one is with the push(). Can you tell me what is wrong with the following code?

"use strict"; // interprets the documents contents in JavaScript strict mode

//global variables var list = {};

function generateList() { var listItems = document.getElementsByTagName("li"); for (var i = listItems.length - 1; i >= 0; i--) { document.getElementsByTagName("ol")[0].removeChild(listItems[i]); } for (var i = 0; i < list.length; i++) { var newItem = "first" + list[i]; var newListItem = document.createElement("li"); newListItem.innerHTML = newItem; document.getElementsByTagName("ol")[0].appendChild(newListItem); var firstButtons = document.querySelectorAll(".first"); var lastFirstButton = firstButtons[firstButtons.length - 1]; if (lastFirstButton.addEventListener) { lastFirstButton.addEventListener("click", moveToTop, false); } else if (lastFirstButton.attachEvent) { lastFirstButton.attachEvent("onclick", moveToTop); } } }

function addItem() { var newItem = document.getElementById("newItem"); list.push(newItem.value); newItem.focus(); newItem.value = ""; generateList(); }

function moveToTop() { if (evt === undefined) { // get caller element in IE8 evt = window.event; } var callerElement = evt.target || evt.srcElement; var listItems = document.getElementsByTagName("li"); var parentItem = callerElement.parentNode; for (var i = 0; i < list.length; i ++) { if (parentItem.innerHTML.search(list[i]) !== -1) { var itemToMove = list.splice(i, 1); list.unshift(itemToMove); } } generateList(); }

function createEventListener() { var addButton = document.getElementById("button"); if (addButton.addEventListener) { addButton.addEventListener("click", addItem, false); } else if (addButton.attachEvent) { addButton.attachEvent("onclick", addItem); } } if (window.addEventListener) { window.addEventListener("load", createEventListener, false); } else if (window.attachEvent) { window.attachEvent("onload", createEventListener); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Databases Technologies And Applications

Authors: Zongmin Ma

1st Edition

1599041219, 978-1599041216

More Books

Students also viewed these Databases questions

Question

How do Dimensional Database Models differ from Relational Models?

Answered: 1 week ago

Question

What type of processing do Relational Databases support?

Answered: 1 week ago

Question

Describe several aggregation operators.

Answered: 1 week ago