javascript - How to check if there is no specific character left -


i'm creating javascript game of hangman (javascript no jquery whatsoever) code replace unguessed letters '_'

function partialwords(random_word, letters) {     var returnletter = "";     (i = 0; < random_word.length; i++) {         if (letters.indexof(random_word[i]) !== -1) {             returnletter = returnletter + random_word[i];         } else {             returnletter = returnletter + ' _ ';         }     }     return returnletter; } 

i wondering if able me figuring out how check if there no more '_' left, in advance!

there indexof method string object too

if(returnletter.indexof('_') == -1) {  } 

you can hold missed letters in separate array

function partialwords(random_word, letters) {     var returnletter = "";     var missedletters = [];     (i = 0; < random_word.length; i++) {         if (letters.indexof(random_word[i]) !== -1) {             returnletter = returnletter + random_word[i];         } else {             returnletter = returnletter + ' _ ';             missedletters.push(random_word[i]);         }     }      if(missedletters.length > 0) {         //         // send missed letters         return missedletters.join(', ');     }     return returnletter; } 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -