Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let info = {init: false};
- let run = word => {
- info = {
- word: word,
- letters: word.split(''),
- discoveries: [],
- correct: 0,
- errors: 0,
- limit_errors: 5,
- }
- render();
- }
- let attempt = (letter) => {
- let result = getLetter(info.letters, letter);
- if(!result){
- console.log("errou");
- return checkDefeat();
- }
- console.log("acertou");
- checkWin(result);
- }
- getLetter = (arr, letter) => {
- let data = arr.filter(arr_letter => letter == arr_letter)
- if(!data.length) return false;
- console.log(data);
- return {
- letter: data[0],
- length: data.length
- }
- }
- let checkWin = result => {
- info.correct += result.length;
- if(info.correct == info.letters.length){
- console.log('win');
- }
- info.discoveries.push(result.letter);
- render();
- }
- checkDefeat = () => {
- info.errors += 1;
- if(info.errors > info.limit_errors){
- console.log('lost');
- }
- }
- render = () => {
- let str = '';
- for(let i = 0, lim = info.word.length; i < lim; i++){
- str += info.discoveries.indexOf(info.word[i]) == -1 ? "_ ": info.word[i] + " ";
- }
- console.log(str);
- }
- // to start the play use function run and send the word what do you want to play
- //run('wordtoplay');
- // to play use function attempt send the letters input
- //attempt('o');
Add Comment
Please, Sign In to add comment