0

I am creating a Kata on Codewars. Its objective is to make a Player with certain attributes and values. This is the complete working solution,

function Player(name, position, age, dribbling, pass, shoot) {
 this.name = name;
 this.position = position;
 this.age = age;
 this.dribbling = dribbling;
 this.pass = pass;
 this.shoot = shoot;
} 

var myPlayer = new Player('Player', 'Right Winger', 25, 75, 90, 65);

And this is the Test Cases I have to provide to validate the complete working solution in order to publish the Kata,

describe('Player class', function () {
  it('should create a Player', function (){
    var myPlayer = new Player()
      Test.assertEquals(myPlayer.name, 'Player')
      Test.assertEquals(myPlayer.position, 'Right Winger')
      Test.assertEquals(myPlayer.age, 25)
      Test.assertEquals(myPlayer.dribbling, 75)
      Test.assertEquals(myPlayer.pass, 90)
      Test.assertEquals(myPlayer.shoot, 65)
    })
})`

And this is the result I get when I run the 'Validate Solution' button,

Player class
should create a Player
Expected: Player, instead got: undefined
Expected: Right Winger, instead got: undefined
Expected: 25, instead got: undefined
Expected: 75, instead got: undefined
Expected: 90, instead got: undefined
Expected: 65, instead got: undefined

0 Passed
6 Failed
0 Errors

What am I doing wrong?

2
  • 2
    because when you call new Player() you pass all parameter undefined Commented Oct 31, 2015 at 10:41
  • There's nothing wrong. You've got result of assertions against your fed code. Check the messages to know how to fix them. Commented Oct 31, 2015 at 10:48

1 Answer 1

1

Here you didn't pass anything

var myPlayer = new Player()

that's why every property of myPlayer is undefined

instead try this

var myPlayer = new Player('Player', 'Right Winger', 25, 75, 90, 65);
Test.assertEquals(myPlayer.name, 'Player');
Test.assertEquals(myPlayer.position, 'Right Winger');
Test.assertEquals(myPlayer.age, 25);
Test.assertEquals(myPlayer.dribbling, 75);
Test.assertEquals(myPlayer.pass, 90);
Test.assertEquals(myPlayer.shoot, 65);
Sign up to request clarification or add additional context in comments.

2 Comments

Now it works, my bad I didn't notice this important feature. The devil is in the details!
glad this helped you :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.