Pen Settings

HTML

CSS

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ 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

              
                <div id="titol"> Construïm una llista de nombres primers </div>
<form action="" id="formulari">
  <div>
		<input type="number" id="nombre" placeholder="Fins els nombre" min ="1"/>
		<input type="submit" id="calcul" value="Calculem-ho" />
  </div>
</form>
<div id="sortida"></div>
              
            
!

CSS

              
                :focus {
	outline-style: none;
  background-color: yellow;
}

input:invalid{
  background-color: #ffdddd;
}

#nombre {
	width: 200px;
	padding: 8px;
	border: 1px solid #ddd;
}	

input[type="submit"] {
	background: DodgerBlue;
	color: #fff;
	padding: 8px 20px;
	border: none;
	border-radius: 16px;
	cursor: pointer;
  margin: 0 40px;
}

input[type="submit"]:hover{
  background: salmon;
}

#titol{
  margin: 15px 0;
  font-family: 'Baloo Bhaijaan', cursive;
  font-size: 22px; 
  color: blue;
}

#sortida {
	font: 1em monospace;
  margin: 5px 0;
  color: red;
}
              
            
!

JS

              
                function* Primer(max) { // Funció generator per nombres primers
  const infinit = !max && max !== 0;
  const re = /^.?$|^(..+?)\1+$/;  // Expressió regular per nombres primers
  let actual = 1;
 
  while (infinit || max-- ) {
      if(!re.test('1'.repeat(actual)) == true) yield actual;
      actual++
  };
};

window.onload = () => { //Carreguem el document HTML
  	
      var calcul = document.querySelector( "#calcul" ),
			    sortida = document.querySelector( "#sortida" ),
          formulari = document.querySelector("#formulari");
      
      formulari.addEventListener( "submit", (e) => {
        e.preventDefault();
        
        var primer = document.querySelector( "#nombre" ).value;
        if (primer == "" || isNaN(primer)) primer = 1;
        
        let [...primers] = Primer(parseInt(primer)); // Posem tots els primers, enters, trobats a la variable
		    sortida.innerHTML = primers;
        
      });
};

              
            
!
999px

Console