SHARE
TWEET

Untitled

a guest Mar 11th, 2017 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.     return function(element, contents) {
  4.  
  5.         if (typeof element === 'string') {
  6.             element = document.getElementById(element);
  7.             if (element == null) {
  8.                 throw Error('element not found');
  9.             }
  10.         } else if (!(element instanceof HTMLElement) || contents == null || contents == undefined) {
  11.             throw Error('invalid element');
  12.         }
  13.  
  14.        for (i = 0; i < contents.length; i += 1) {
  15.     if (typeof contents[i] !== 'string' && typeof contents[i] !== 'number') {
  16.         throw Error('contents must contain ony numbers and strings');
  17.     }
  18. }
  19.  
  20.         //delete the element content
  21.         element.textContent = '';
  22.         //contents = [1,2,3,3,4,'tsvet'];
  23.  
  24.       for(i = 0; i < contents.length;i+=1){
  25.          var newEl = document.createElement('div');
  26.             newEl.textContent = contents[i];
  27.             element.appendChild(newEl);
  28.      }  
  29.      
  30.     }
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top