Code Wars Help: Creating Objects & Assigning Values

Code Wars Help: Creating Objects & Assigning Values


I’m doing what is supposedly a super easy kata on CodeWars and I think I missed something on my learning journey because I’m stuck. Can anyone point me in the right direction? (Without giving me the answer straight out?)

Regular Ball Super Ball

Create a class Ball.

Ball objects should accept one argument for “ball type” when instantiated.

If no arguments are given, ball objects should instantiate with a “ball type” of “regular.”

ball1 = new Ball();
ball2 = new Ball(“super”);

ball1.ballType //=> "regular"
ball2.ballType //=> “super”

And here’s my answer:

var Ball = function(ballType) {
  if (ballType === undefined) {
     this.ballType = "regular";

var ball1 = new Ball();
var ball2 = new Ball("super");

My two test cases are:

Test.assertEquals(new Ball().ballType, "regular");
Test.assertEquals(new Ball("super").ballType, "super");

My solution passes the first test but not the second. What am I doing wrong?


you are handling only the case when argument is not provided.
What about the case when argument is provided? :bulb:


Ah! Thank you so much! How could I have forgotten that?