Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while testing: "TypeError: game.check is not a function" rock, paper scissors JS #41

Open
Carrosen opened this issue Apr 28, 2019 · 0 comments

Comments

@Carrosen
Copy link

Problem

I get an error saying game.check is not a function.

Background

Used material for fizzbuzz Javascript challenge as template.
The error came up as after I changed the naming of functions and values to fit my game.
I feel like my whole code is kind of a mess, I apologize in advance

Spec

describe('Game', () => {
    let game = new Game
    let Player1 = ('button1').value
    let Player2 = ('button2').value

    describe('Player1 wins', () => {

        it('returns Player1 is the winner if Player1 enters "rock" and Player2 enters "scissors"', () => {
            expect(game.check(Player1, Player2)).to.eql("Player1 is the winner!")
        })

        it('returns Player1 is the winner if Player1 enters "paper" and Player2 enters "rock"', () => {
            expect(game.check(Player1, Player2)).to.eql("Player1 is the winner!")
        })

        it('returns Player1 is the winner if Player1 enters "scissors" and Player2 enters "paper"', () => {
            expect(game.check(Player1, Player2)).to.eql("Player1 is the winner!")
        })
    })


    describe('Player2 wins', () => {

        it('returns Player2 is the winner if Player2 enters "rock" and Player1 enters "scissors"', () => {
            expect(game.check(Player1, Player2)).to.eql("Player2 is the winner!")
        })

        it('returns Player2 is the winner if Player2 enters "paper" and Player1 enters "rock"', () => {
            expect(game.check(Player1, Player2)).to.eql("Player2 is the winner!")
        })

        it('returns Player2 is the winner if Player2 enters "scissors" and Player1 enters "paper"', () => {
            expect(game.check(Player1, Player2)).to.eql("Player2 is the winner!")
        })
    })

    describe('Its a tie!', () => {
        
        it('returns Its a tie! if Player1 == Player2', () => {
            expect(game.check(Player1 == Player2)).to.eql("Its a tie!")
        })

    })

})

Implementation code

game.js

function Game() {
    let Player1 = ('button1').value
    let Player2 = ('button2').value
    this.check = (Player1, Player2)
  
            if (Player1 === Player2) {
                return 'Its a tie!';
            } 
        
            else if ((Player1 === "rock") && (Player2 === "scissors")) {
                return 'Player1 is the winner!';
            }
            else if ((Player1 === "rock") && (Player2 === "paper")) {
                return 'Player2 is the winner!';
            }
            else if ((Player1 === "paper") && (Player2 === "rock")) {
                return 'Player1 is the winner!';
            }
            else if ((Player1 === "paper") && (Player2 === "scissors")) {
                return 'Player2 is the winner!';
            }
            else if ((Player1 === "scissors") && (Player2 === "paper")) {
                return 'Player1 is the winner!';
            }
            else if ((Player1 === "scissors") && (Player2 === "rock")) {
                return 'Player2 is the winner!';
            }
            else {
                return 'That is not the game pal, try "rock", "paper" or "scissors"';
            }
    }

application.js

  it('clicking on the "Check" button', async () => {
    await browser.fillIn("input[id='value1']", { with: "rock" })
    await browser.clickOnButton("#button1")
    await browser.fillIn("input[id='value2']", { with: "rock" })
    await browser.clickOnButton("#button2")
    await browser.clickOnButton("#button3")
    let content = await browser.getContent("[id='display_answer']")
    expect(content).to.eql('Its a tie!');

  })

How did you try to solve the problem?

I think it has to do with the naming of different values, so I tried to figure out what and changed a bunch of them.
I have tried to google the error and on other RPS games, going through the material once again. I think it's more than one typo or wrong naming problem here so I found it hard to figure it out.

@Carrosen Carrosen changed the title game.check is not a function. rock, paper scissors JS Error while testing: game.check is not a function. rock, paper scissors JS Apr 28, 2019
@Carrosen Carrosen changed the title Error while testing: game.check is not a function. rock, paper scissors JS Error while testing: "TypeError: game.check is not a function" rock, paper scissors JS Apr 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant