這個章節要介紹Number
的物件,Number
物件是以Number()
建構子來建立的。
語法new Number(value);
參數value
:用來建立物件的數值。
Number 物件主要的用途:
用 Number.Properties()
來判斷是哪一個內建的屬性。
中間的Properties請用已有的屬性去替換。
常見的Properties屬性:
其他屬性可參考這篇文章“Number”
今天的練習題就是要判斷屬性,並回傳對應屬性文字內容:
Task
Coding in function whatNumberIsIt. function accept 1 parameter:n. it's a number.
To judge the number n. If n is one of the above five constants, return one of these string:
"Input number is Number.MAX_VALUE"
"Input number is Number.MIN_VALUE"
"Input number is Number.NaN"
"Input number is Number.NEGATIVE_INFINITY"
"Input number is Number.POSITIVE_INFINITY"
這是我的作法:
function whatNumberIsIt(n){
switch(n){
case Number.MAX_VALUE: return "Input number is Number.MAX_VALUE"
case Number.MIN_VALUE : return "Input number is Number.MIN_VALUE"
case Number.POSITIVE_INFINITY : return "Input number is Number.POSITIVE_INFINITY"
case Number.NEGATIVE_INFINITY : return "Input number is Number.NEGATIVE_INFINITY"
case Number(n): return "Input number is "+ n;
default: return "Input number is Number.NaN";
}
}