Last active
August 29, 2015 14:20
-
-
Save sajadtorkamani/ba3bd4f58e00eae04f0a to your computer and use it in GitHub Desktop.
Getting position of occurrences of a guessed letter in a given word (Hangman).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(document).ready(function() { | |
function getChar(string, position) | |
{ | |
var char = string.charAt(position); | |
console.log(char); | |
} | |
function getPositions(correctWord, guess) | |
{ | |
var positions = []; | |
for(var i = 0; i < correctWord.length; i++) | |
{ | |
var letter = correctWord.charAt(i); | |
if(letter.indexOf(guess) !== -1) | |
{ | |
positions.push(i); | |
} | |
} | |
return positions; | |
} | |
console.log(getPositions("braian", "a")); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment