-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathscript.js
More file actions
28 lines (22 loc) · 1.04 KB
/
script.js
File metadata and controls
28 lines (22 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"use strict";
const textAreaList = document.querySelectorAll("textarea");
const buttonsList = document.querySelectorAll(".btn");
const lengthItems = document.querySelectorAll(".heading");
const updateLengthAndMatchStatus = (index) => {
const textFromWindow1 = textAreaList[index].value;
const textFromWindow2 = textAreaList[index + 1].value;
// Update the length display
lengthItems[index].textContent = `Length: ${textFromWindow1.length}`;
lengthItems[index + 1].textContent = `Length: ${textFromWindow2.length}`;
// Determine match status
const isMatched = textFromWindow1 === textFromWindow2;
updateMatchClasses(textAreaList[index], isMatched);
updateMatchClasses(textAreaList[index + 1], isMatched);
};
const updateMatchClasses = (textArea, isMatched) => {
textArea.classList.toggle("matched", isMatched);
textArea.classList.toggle("un-matched", !isMatched);
};
buttonsList.forEach((btn, index) => {
btn.addEventListener("click", () => updateLengthAndMatchStatus(index * 2));
});