Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's 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 it's URL and the proper URL extention.

+ add another resource


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


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.


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.






                class Prime {
  constructor(limit) {
    this.limit = limit;
  *[Symbol.iterator]() {
    let limit = this.limit;
    let isPrime = true;
    for (let value = 2; value <= limit; value++) {
      for (let divisor = value - 1; divisor > 1; divisor--) {
        if (value % divisor === 0) {
          isPrime = false;
      if (isPrime) yield value;
      isPrime = true;

function PrimeFactor(value) {
    let primer = new Prime(value); // generates prime numbers up to number
    let number = value; // find prime factors for this number
    let primes = [...primer]; // get the primes
    let factors = []; // store the factors
    let product = 0;  // tracks current product of factors found
    let remainder = number; // track remainder after found factor is removed
    while (product < number) { // check if product of all factors is our number
      for (let factor of primes) {
        if (remainder % factor === 0) {
          product = factors.reduce((product,factor) => product * factor, 1);
          remainder = (product !== 0) ? (number / product) : remainder; // factor is removed
      // update product by multiplying each of the factors
    return factors;


function lcm(arr) {
  let [lowest,highest] = (arr[0] - arr[1] <= 0) ? arr : arr.reverse();
  let factors = PrimeFactor(highest);
  //  Loop through factors of highest value and see if any factor of lowest value matches
  // if factor is not found can add that to our factors
  for (let factor of PrimeFactor(lowest)) {
    if (!(factors.some( value => value === factor ))) factors.push(factor);
  console.log(`factors: ${factors}`);
  return factors.reduce((product,factor) => product * factor, 1);

let values = [7,25];
let leastCommonMultiple = lcm(values);
console.log(`LCM for ${values.join(' and ')} is ${leastCommonMultiple}`);