-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
44 lines (36 loc) · 1.49 KB
/
index.js
File metadata and controls
44 lines (36 loc) · 1.49 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
import anagramChecker from "./modules/anagramChecker.js";
const form = document.getElementById("js-form");
const stringInput1 = document.getElementById("js-str1");
const stringInput2 = document.getElementById("js-str2");
const output = document.getElementById("js-output");
const successTextClass = "anagram-checker__output--success";
const failureTextClass = "anagram-checker__output--danger";
const addAndRemoveClasses = (element, classToAdd, classToRemove) => {
element.classList.remove(classToRemove);
element.classList.add(classToAdd);
return null;
};
form.addEventListener("submit", (event) => {
event.preventDefault();
const string1 = stringInput1.value;
const string2 = stringInput2.value;
if (anagramChecker(string1, string2)) {
if (string1 === "" || string2 === "") {
addAndRemoveClasses(output, successTextClass, failureTextClass);
output.innerHTML = "As both strings are empty, they are anagram";
} else {
addAndRemoveClasses(output, successTextClass, failureTextClass);
output.innerHTML = `"${string1}" and "${string2}" are anagram`;
}
} else {
if (string1 === "" || string2 === "") {
addAndRemoveClasses(output, failureTextClass, successTextClass);
output.innerHTML = "As one string is empty, they are not anagram";
} else {
addAndRemoveClasses(output, failureTextClass, successTextClass);
output.innerHTML = `"${string1}" and "${string2}" are not anagram`;
}
}
});
stringInput1.focus();
export default null;