Javascript String isUpperCase()

Description

Javascript String isUpperCase()


//define the string prototype here
String.prototype.isUpperCase = function(){

if(this==this.toUpperCase() ){
   return true;//w  w  w . j  av  a 2  s . c  om
}
else return false;
}

Javascript String isUpperCase()

// "c".isUpperCase() == false
// "C".isUpperCase() == true
// "hello I AM DONALD".isUpperCase() == false
// "HELLO I AM DONALD".isUpperCase() == true
// "ACSKLDFJSgSKLDFJSKLDFJ".isUpperCase() == false
// "ACSKLDFJSGSKLDFJSKLDFJ".isUpperCase() == true

String.prototype.isUpperCase = function() {
  return this.toString() === this.toUpperCase();
}

String.prototype.isUpperCase = function() {
  for(let ch of this) {
    if (!/[A-Z\W]/.test(ch)) {
      return false
    }//from  w w w  .j a  va2  s .c  om
  }
  return true
}

Javascript String isUpperCase()

// Is the string uppercase?
////from  w  ww  .j a v a 2  s . c  om
// Task
//
// Create a method is_uppercase() to see whether the string is ALL CAPS. For example:
//
// Corner Cases
//
// For simplicity, you will not be tested on the ability to handle corner cases (e.g. "%*&#()%&^#" or similar strings containing alphabetical characters at all) - an ALL CAPS (uppercase) string will simply be defined as one containing no lowercase letters. Therefore, according to this definition, strings with no alphabetical characters (like the one above) should return True.

String.prototype.isUpperCase = function () {
  if (this.valueOf().toUpperCase() === this.valueOf()) {
  return true;
} else
  return false;
}



PreviousNext

Related