What is your hint or solution suggestion?
A type helps group similar values on which common operations can be performed. The error messages are defined using the TypeError()
function based on certain conditions. Set the integer to this._value
, then return it using the Num.prototype.valueOf
method.
Solution 1
function Num(n){
if(isNaN(n))
throw new TypeError("Not a Number");
if(n < 1 || n > 10)
throw new TypeError("Out of range");
this._value = n;
}
Num.prototype.valueOf = function() { return this._value; }
Num.prototype.toString = function () { return this._value.toString();}
Challenge: Define a primitive data type
Link to the challenge: