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

Save Automatically?

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

              
                //Write a function that will return an array with all of the numbers from 1 to 255.
function range(start, end) {
  return Array(end - start + 1).fill().map((_, idx) => start + idx)
}
var result = range(1,255); //numbers 1 to 255
console.log(result); //of array

//Next Question: Write a function that will return the summ of all the even numbers from 1 to 1000.
let sum=0
for(i=1; i<=1000;i++){
  if(i%2===0){
    sum=sum+i
  }
}
console.log(sum)
//end even numbers task

//3.) Write a function that returns the sum of all the odd numbers from 1 to 5000.
function isOdd(n) {
  return Boolean(n % 2);
}

function findSum(no) {
  let sum = 0;

  for (var i = 0; i < no; i++) {
    if (isOdd(i)) {
      sum += i;
    }
  }
  return sum;
}

console.log(findSum(5000));


// 4.) Write a function that returns the sum of all the values within an array.
// (e.g. [1,2,5] returns 8, [-5,2,5,12] returns 14).
let data = [1, 2, 5];

sum = data.reduce((a, b) => {
  return a + b;
});

console.log('The sum is: ', sum);

// 5.) Given an array with multiple values,
// write a function that returns the maximum number in the array.
console.log(Math.max(1, 3, 2, 7, 23, 56, 100));


// 6.) Given an array with multiple values,
//  write a function that returns the average of the values in the array.
// [1,3,5,7,20] average is 7.2
arry = [1, 3, 5, 7, 20];

function calculateAverage(array) {
    var total = 0;
    var count = 0;

    array.forEach(function(item, index) {
        total += item;
        count++;
    });

    return total / count;
}

console.log(calculateAverage(arry));


// 7.) Write a function that would return an array of all the odd numbers between 1 to 50.
console.log(Array(25).fill(2).map((x, i) => i * x + 1).join(', ')) 
              
            
!
999px

Console