I need to write a constructor for an object that gives a random value to the object's color property. This is what I wrote
var Ghost = function() {
// your code goes here
var num = Math.floor(Math.rand()*4);
if(num === 0){
this.color = "white";
}
else if(num === 1){
this.color = "yellow";
}
else if(num === 2){
this.color = "purple";
}
else if(num === 3){
this.color = "red";
}
};
I get an error message from the test suite on code wars
TypeError: Object #<Object> has no method 'rand'
at new Ghost
at Test.describe
Am I not allowed to use functions inside a constructor or is there something about the test suite I don't understand?
Math.random()? There's noMath.rand()function.