forked from Sulagna-Dutta-Roy/GGExtensions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
34 lines (30 loc) · 932 Bytes
/
script.js
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
function anagramChecker(){
const word1 = document.querySelector('.js-word1').value.trim();
const word2 = document.querySelector('.js-word2').value.trim();
let resultVal = document.querySelector('.js-result');
if (word1 === '' && word2 === ''){
resultVal.innerHTML = 'Please enter both words';
}
else if (word1 === ''){
resultVal.innerHTML = 'Please enter word 1';
}
else if (word2 === ''){
resultVal.innerHTML = 'Please enter word 2';
}
else{
const newText1 = word1.toLowerCase().split('').sort().join('');
const newText2 = word2.toLowerCase().split('').sort().join('');
if(newText1 === newText2){
resultVal.innerHTML = 'Anagrams';
resultVal.style.color = 'green';
}
else{
resultVal.innerHTML = 'Not Angrams';
resultVal.style.color = 'red';
}
}
}
document.querySelector('.js-submit')
.addEventListener('click', () => {
anagramChecker();
});