javascript - How to Check whether a given word contains in String? -


please have @ following code

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>untitled document</title>  <script> function count() {     var listofwords, paragraph, listofwordsarray, paragrapharray;     var wordcounter=0;      listofwords = document.getelementbyid("wordslist").value;      //split words     listofwordsarray = listofwords.split("\n");      //get paragrah text     paragraph = document.getelementbyid("paragraph").value;     paragrapharray = paragraph.split(" ");      //check whether paragraph contains words in list     for(var i=0; i<listofwordsarray.length; i++)     {         if(paragraph.contains(wordlistarray[i]))         {                 wordcounter++;         }     }      window.alert("number of contains: "+wordcounter); } </script>  </head>   <body> <center> <p> enter word list here </p> <br /> <textarea id="wordslist" cols="100" rows="10"></textarea>  <br /> <p>enter paragraph here</p> <textarea id="paragraph" cols="100" rows="15"></textarea>  <br /> <br /> <button id="btn1"  onclick="count()">calculate percentage</button>  </center> </body> </html> 

here, trying counting how number of words in paragraph included in wordlist. words in wordlist separated new line.

however, not getting output here. yes, nothing. not web , scripting languages failed find going behind.

please me in counting how number of words in paragraph included in wordlist. , please explain why not getting displayed.

you had typo

//check whether paragraph contains words in list for(var i=0; i<listofwordsarray.length; i++) {     if(paragraph.contains(wordlistarray[i]))     { 

see wordlistarray doesn't exist, should listofwordsarray

see here http://jsfiddle.net/pw7jz/


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -