JS bad words counter [closed]
I try to count bad words on a string, but my code always shows 0. What is wrong?
function checkWord(list){
var j = 0;
var badWords = ["war", "bomb"]; //bad word list
for(var i = 0; i<badWords.lenght; i++){
if( list.toLowerCase().search(badWords[i])) j++; //check is it bad word in sting if true j+1
}
return j;
}
console.log(checkWord("sfasdf dgfdfsg sdfsA bomb war"));
Always returns: 0 Should be: 2
javascript count
closed as off-topic by epascarello, Carcigenicate, Sebastian Speitel, Patrick Evans, Tyler Roper Nov 16 '18 at 16:11
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – epascarello, Carcigenicate, Sebastian Speitel, Patrick Evans, Tyler Roper
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I try to count bad words on a string, but my code always shows 0. What is wrong?
function checkWord(list){
var j = 0;
var badWords = ["war", "bomb"]; //bad word list
for(var i = 0; i<badWords.lenght; i++){
if( list.toLowerCase().search(badWords[i])) j++; //check is it bad word in sting if true j+1
}
return j;
}
console.log(checkWord("sfasdf dgfdfsg sdfsA bomb war"));
Always returns: 0 Should be: 2
javascript count
closed as off-topic by epascarello, Carcigenicate, Sebastian Speitel, Patrick Evans, Tyler Roper Nov 16 '18 at 16:11
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – epascarello, Carcigenicate, Sebastian Speitel, Patrick Evans, Tyler Roper
If this question can be reworded to fit the rules in the help center, please edit the question.
lenght != length
– epascarello
Nov 16 '18 at 16:09
2
it should belength
notlenght
and after changing it I got 2 as output
– Curious_Mind
Nov 16 '18 at 16:10
add a comment |
I try to count bad words on a string, but my code always shows 0. What is wrong?
function checkWord(list){
var j = 0;
var badWords = ["war", "bomb"]; //bad word list
for(var i = 0; i<badWords.lenght; i++){
if( list.toLowerCase().search(badWords[i])) j++; //check is it bad word in sting if true j+1
}
return j;
}
console.log(checkWord("sfasdf dgfdfsg sdfsA bomb war"));
Always returns: 0 Should be: 2
javascript count
I try to count bad words on a string, but my code always shows 0. What is wrong?
function checkWord(list){
var j = 0;
var badWords = ["war", "bomb"]; //bad word list
for(var i = 0; i<badWords.lenght; i++){
if( list.toLowerCase().search(badWords[i])) j++; //check is it bad word in sting if true j+1
}
return j;
}
console.log(checkWord("sfasdf dgfdfsg sdfsA bomb war"));
Always returns: 0 Should be: 2
function checkWord(list){
var j = 0;
var badWords = ["war", "bomb"]; //bad word list
for(var i = 0; i<badWords.lenght; i++){
if( list.toLowerCase().search(badWords[i])) j++; //check is it bad word in sting if true j+1
}
return j;
}
console.log(checkWord("sfasdf dgfdfsg sdfsA bomb war"));
function checkWord(list){
var j = 0;
var badWords = ["war", "bomb"]; //bad word list
for(var i = 0; i<badWords.lenght; i++){
if( list.toLowerCase().search(badWords[i])) j++; //check is it bad word in sting if true j+1
}
return j;
}
console.log(checkWord("sfasdf dgfdfsg sdfsA bomb war"));
javascript count
javascript count
asked Nov 16 '18 at 16:09
evaldas.z.oevaldas.z.o
173
173
closed as off-topic by epascarello, Carcigenicate, Sebastian Speitel, Patrick Evans, Tyler Roper Nov 16 '18 at 16:11
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – epascarello, Carcigenicate, Sebastian Speitel, Patrick Evans, Tyler Roper
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by epascarello, Carcigenicate, Sebastian Speitel, Patrick Evans, Tyler Roper Nov 16 '18 at 16:11
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – epascarello, Carcigenicate, Sebastian Speitel, Patrick Evans, Tyler Roper
If this question can be reworded to fit the rules in the help center, please edit the question.
lenght != length
– epascarello
Nov 16 '18 at 16:09
2
it should belength
notlenght
and after changing it I got 2 as output
– Curious_Mind
Nov 16 '18 at 16:10
add a comment |
lenght != length
– epascarello
Nov 16 '18 at 16:09
2
it should belength
notlenght
and after changing it I got 2 as output
– Curious_Mind
Nov 16 '18 at 16:10
lenght != length
– epascarello
Nov 16 '18 at 16:09
lenght != length
– epascarello
Nov 16 '18 at 16:09
2
2
it should be
length
not lenght
and after changing it I got 2 as output– Curious_Mind
Nov 16 '18 at 16:10
it should be
length
not lenght
and after changing it I got 2 as output– Curious_Mind
Nov 16 '18 at 16:10
add a comment |
1 Answer
1
active
oldest
votes
Please find the below snapshot, this might help :)
function checkWord(list){
var j = 0;
var badWords = ["war", "bomb"]; //bad word list
badWords.forEach(word => {
list.includes(word) && j ++
})
return j
}
console.log(checkWord("sfasdf dgfdfsg sdfsA bomb war"));
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Please find the below snapshot, this might help :)
function checkWord(list){
var j = 0;
var badWords = ["war", "bomb"]; //bad word list
badWords.forEach(word => {
list.includes(word) && j ++
})
return j
}
console.log(checkWord("sfasdf dgfdfsg sdfsA bomb war"));
add a comment |
Please find the below snapshot, this might help :)
function checkWord(list){
var j = 0;
var badWords = ["war", "bomb"]; //bad word list
badWords.forEach(word => {
list.includes(word) && j ++
})
return j
}
console.log(checkWord("sfasdf dgfdfsg sdfsA bomb war"));
add a comment |
Please find the below snapshot, this might help :)
function checkWord(list){
var j = 0;
var badWords = ["war", "bomb"]; //bad word list
badWords.forEach(word => {
list.includes(word) && j ++
})
return j
}
console.log(checkWord("sfasdf dgfdfsg sdfsA bomb war"));
Please find the below snapshot, this might help :)
function checkWord(list){
var j = 0;
var badWords = ["war", "bomb"]; //bad word list
badWords.forEach(word => {
list.includes(word) && j ++
})
return j
}
console.log(checkWord("sfasdf dgfdfsg sdfsA bomb war"));
function checkWord(list){
var j = 0;
var badWords = ["war", "bomb"]; //bad word list
badWords.forEach(word => {
list.includes(word) && j ++
})
return j
}
console.log(checkWord("sfasdf dgfdfsg sdfsA bomb war"));
function checkWord(list){
var j = 0;
var badWords = ["war", "bomb"]; //bad word list
badWords.forEach(word => {
list.includes(word) && j ++
})
return j
}
console.log(checkWord("sfasdf dgfdfsg sdfsA bomb war"));
answered Nov 16 '18 at 16:14
Arulmozhi ManikandanArulmozhi Manikandan
1766
1766
add a comment |
add a comment |
lenght != length
– epascarello
Nov 16 '18 at 16:09
2
it should be
length
notlenght
and after changing it I got 2 as output– Curious_Mind
Nov 16 '18 at 16:10