I am looking to create a function that will determine whether a given value is a percentage. The function should return true for numbers followed by a '%' symbol or decimal values representing percentages.
Here's how I want it to work:
/* input value ... return value */
percentage_check("21%") == true
percentage_check("21") == true
percentage_check("0.21") == true
percentage_check(21) == true
percentage_check(0.21) == true
percentage_check(121) == false //numbers above 100%
percentage_check(1.21) == true
percentage_check("twenty") == false
How should this function be implemented?
function percentage_check(n) {
//code
}