0
var hangman = {
    random: Math.floor((Math.random() * 3)),
    word_bank: ["hello", "bye", "hey"],
    select: "",
    guess: "",
    wins: 0,
    loss: 0,
    dashs: [],
    split: [],
    correct_letter: [],
    replace_dash: [],
    alphabet:['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'
],
    select_word: function() {
        this.select = this.word_bank[this.random];
    },
    dash: function() {
        for (var i = 0; i < this.select.length; i++) {
            if (this.select[i] == " ") {
                this.dashs.push("&nbsp;");
            } else {
                this.dashs.push("_");    
            }
        }
    },
    split: function() {
        this.split = this.select.split("");
    },
    correct_i: function() {
        for (var i = this.select.length - 1; i >= 0; i--) {
            if (this.split[i] == this.guess) {
                this.correct_letter.push(i)
            }
        }        
    },
    replace_dash: function(){
        for (var i =  0; i < this.correct_letter.length; i++) {
            this.dash[this.correct_letter[i]] = this.guess;
        }
    },
    board_set: function(){
        this.select_word();
        this.dash();
        this.split();
        this.correct_letter = [];
        this.replace_dash = [];
    },
    play_game: function(){
        this.board_set();
        console.log(hangman.dashs);
        console.log(hangman.split);
        var alphabet = this.alphabet;
        var gameboard = $("#game");
        gameboard.html("<p>Game Board</p>" + this.dashs.join(" "));
            document.onkeyup = function(e){
                this.guess = String.fromCharCode(e.keyCode).toLowerCase();
                if (alphabet.indexOf(this.guess) >= 0) {
                    this.correct_i();
                    this.replace_dash();
                    console.log(correct_i);
                    console.log(replace_dash);
                    gameboard = $("#game");
                    gameboard.html("<p>Game Board</p>" + this.dashs.join(" "));
                }
            }
    }
};
hangman.guess = "e";

Within the play_game() I am trying to call the other methods within this method, but it keeps saying that the methods I am calling are not defined. I have tried to do:

hangman.correct_i();
hangman.replace_dash();

and that doesn't work either.

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
Justin Besteman
  • 378
  • 1
  • 6
  • 17
  • 1
    You've reused the property `split` for two different purposes, an array and a method. ...same with `replace_dash`. –  Oct 18 '16 at 22:40
  • Actually calling `hangman.…()` *does* work, you just have to use `hangman.guess` and `hangman.dashs` as well. – Bergi Oct 18 '16 at 22:41
  • You can try calling hangman.methodname or this.method name either way of calling works – Geeky Oct 18 '16 at 22:42

0 Answers0