-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
50 lines (35 loc) · 1.42 KB
/
app.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
35
36
37
38
39
40
41
42
43
44
function Checker( keywordArr ) {
var result;
this.check = function( postText ) {
var stringLowerCased = postText.toLowerCase();
var keywordArrLength = keywordArr.length;
var keywordCount = 0;
for ( var i = 0; i < keywordArrLength; i++ ) {
var keyword = keywordArr[i];
if ( postText.indexOf( keyword ) > -1 ) {
keywordCount++;
}
}
if ( keywordCount >= keywordArrLength / 4 ) {
result = "It's a scam.";
} else if ( keywordCount >= keywordArrLength / 8 ) {
result = "It's possibly a scam.";
} else {
result = "It might not be a scam or it can be a new one. Please do more research.";
}
console.log(keywordCount);
}
this.getResult = function() {
return result;
};
}
var scamKeywords = ["wire", "post", "uk", "keys", "id", "country", "mail", "out", "deposit", "transfer", "00", "number", "large kitchen", "available", "united kingdom", "family", "honest", "back", "job"];
var button = document.getElementById("button");
var resultText = document.getElementById("result");
button.addEventListener("click", function( event ) {
event.preventDefault()
var postText = document.getElementById("postText").value;
var checker = new Checker( scamKeywords );
checker.check( postText );
resultText.textContent = checker.getResult();
});