Cengage MindTap Tech Screen 1

by Matthew Vasallo

HTML

<ul id="theList">
  <li>6</li>
  <li>3</li>
  <li>1</li>
  <li>4</li>
  <li>7</li>
  <li>4</li>
  <li>2</li>
  <li>8</li>
  <li>9</li>
  <li>2</li>
</ul>

JavaScript

/*
Write a function that does the following
1. Retrieves the list of numbers on the page to the right using the DOM.
2. Finds the first duplicate in that list of numbers and returns that number.

For this example the function would return 4, for the list above.
*/
let seen = new Set([]);
let liCollection = document.getElementById("theList").children;
for (let i = 0; i < liCollection.length; i++) {
  if (seen.has(liCollection[i].innerHTML)) {
     
  }
}
/* document.getElementById("theList").children.forEach(li => {
console.log(li);
}); */