Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                /**
 * Check parameter 
 * Method returns an object with status and response
 * If status:false the response contains all checks and their details
 * If status:true the response contains the generated <li> HTML
 */

const parameter = {
  /** Get final result for all checks. true if there were errors (one status value is false) */
  status: function status(arrCheck){
    return arrCheck.map(obj => Object.values(obj).map(objCheckValue => objCheckValue.status).includes(false)).includes(true);
  },
  /** Check parameters */ 
  check: function check(val,type){
 
    let boolStatus;
    switch(type){
        /** array? */
      case 'typeArray':
        boolStatus = (Array.isArray(val));  
        return {
          status: boolStatus,
          msg: (boolStatus) ? 'Is an array!' : 'Must be an array!'
        }
        break;
        /** array empty ? */      
      case 'emptyArray':
        boolStatus = (val.length > 0);
        return {
          status: boolStatus,
          msg: (boolStatus) ? 'Contains items!' : 'Is empty!'
        }                
        break;
        /** String? */      
      case 'typeString':
        boolStatus = (typeof val === 'string');
        return {
          status: boolStatus,
          msg: (boolStatus) ? 'Is a string!' : 'Must be a string!'
        }           
        break;
        /** String? */      
      case 'emptyString':
        boolStatus = (val.length > 0);
        return {
          status: boolStatus,
          msg: (boolStatus) ? 'Contains charakters!' : 'Is empty!'
        } 
        break;      
        /** Integer? */
      case 'typeInt':
        boolStatus = (Number.isInteger(val));
        return {
          status: boolStatus,
          msg: (boolStatus) ? 'Is an integer!' : 'Must be an integer!'
        }               
        break;
    } 
    
}
  
}

/****
 * Classes
 ****/
  class Data{
    
    /** Method */
    createList(arr,str){
       /**
        * Check parameters
        *** 
        * arrCheck contains all checks and their details
        * - Which parameter and what should be checked?    
        */   
         let arrCheck = [
           {
             typeArray: parameter.check(arr,'typeArray'),
             emptyArray: parameter.check(arr,'emptyArray'),
           },
           {
             typeString: parameter.check(str,'typeString')
           }     
         ]

      /** 
       * Get the final result for the parameter check. true if there were errors (one status value is false)
       */   
        let objCheckResult = parameter.status(arrCheck);

      /** 
       * Paramter error(s). return stop also the code here.
       */
        if(objCheckResult === true){
         console.log('Es gab Fehler bei den Parametern!', arrCheck);
         return {
           status: false,
           response: arrCheck
         }
        }

      /** 
       * Paramter(s) are fine. Execute the method script and return status and response.
       */    
        let arrLi = arr.map(item => `<li>${item}</li>`);
        return {
          status: true,
          response: arrLi
        }
    }
  }

/****
 * Script
 ****/

  /** Array */
  const arrMovies = [
    'Batman Begins',
    'Prometheus',
    'I Am Legend'
  ];
  
  /** Objekt der Klasse Data erzeugen */
  const movies = new Data();
  
  /** Methode ausführen und Parameter übergeben, die geprüft werden */
  // const objCheckedResult = movies.createList(arrMovies,3);       // status: false
  // const objCheckedResult = movies.createList(2,2);               // status: false
  const objCheckedResult = movies.createList(arrMovies,'Movies');   // status: true

  /** Log the result object of checked parameters */
  console.log('result: ', objCheckedResult);



              
            
!
999px

Console