JS bad words counter [closed]












0















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










share|improve this 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 be length not lenght and after changing it I got 2 as output

    – Curious_Mind
    Nov 16 '18 at 16:10


















0















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










share|improve this 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 be length not lenght and after changing it I got 2 as output

    – Curious_Mind
    Nov 16 '18 at 16:10
















0












0








0








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










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 be length not lenght 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






  • 2





    it should be length not lenght 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














1 Answer
1






active

oldest

votes


















1














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"));








share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    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"));








    share|improve this answer




























      1














      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"));








      share|improve this answer


























        1












        1








        1







        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"));








        share|improve this answer













        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"));






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 16:14









        Arulmozhi ManikandanArulmozhi Manikandan

        1766




        1766















            這個網誌中的熱門文章

            Xamarin.form Move up view when keyboard appear

            Post-Redirect-Get with Spring WebFlux and Thymeleaf

            Anylogic : not able to use stopDelay()