-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (49 loc) · 1.78 KB
/
Copy pathscript.js
File metadata and controls
61 lines (49 loc) · 1.78 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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//elements selected for counting
var input = document.querySelector('#input');
var characterCount = document.querySelector('#characters-count');
var wordCount = document.querySelector('#words-count');
var sentenceCount = document.querySelector('#sentences-count');
var paragraphCount = document.querySelector('#paragraphs-count')
//elements selected for tool tip
var infoIcons = document.querySelectorAll('.info-icon');
var tooltipTexts = document.querySelectorAll('.tooltip-text');
//tooltip text should be hidden when the page loads for the first time
//doing this thru js
tooltipTexts.forEach(function (tooltip) {
tooltip.style.display = 'none';
});
// count logic
input.addEventListener('input', function () {
if (input.value) {
//character count
characterCount.innerHTML = input.value.length;
//word count
wordArray = input.value.split(" ").filter((word) => word != "");
wordCount.innerHTML = wordArray.length;
//setence count
sentenceArray = input.value.split(/[.!?]/)
sentenceCount.innerHTML = sentenceArray.length - 1;
//paragraph count
paragraphArray = input.value.split("\n\n").filter((emptySpace) => emptySpace.trim() != "");
paragraphCount.innerHTML = paragraphArray.length;
}
else {
characterCount.innerHTML = 0;
wordCount.innerHTML = 0;
sentenceCount.innerHTML = 0;
paragraphCount.innerHTML = 0;
}
})
//tool tip logic
var toggleTooltip = function (tooltip) {
if (tooltip.style.display === 'none') {
tooltip.style.display = 'block';
} else {
tooltip.style.display = 'none';
}
};
infoIcons.forEach(function (icon, index) {
icon.addEventListener('click', function () {
toggleTooltip(tooltipTexts[index]);
});
});