JavaScript preprocessors can help make authoring JavaScript easier and more convenient. For instance, CoffeeScript can help prevent easy-to-make mistakes and offer a cleaner syntax and Babel can bring ECMAScript 6 features to browsers that only support ECMAScript 5.

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.

You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.

If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.

You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.

+ add another resource

` ````
<html>
<head>
<link rel="stylesheet" type="text/css" href="assets/stylesheets/css/main.css">
</head>
<body>
<div class="tdc-grid"></div>
<script src="assets/js/jquery-3.2.1.min.js"></script>
<script src="assets/js/underscore.js"></script>
<script src="assets/js/sieve.js"></script>
</body>
</html>
```

` ````
.tdc-grid {
&-item {
display: inline-block;
float: left;
margin: 5px;
padding: 10px;
width: 30px;
border-radius: 2px;
text-align: center;
background: #c5d8fc;
color: white;
box-shadow: 0 0 1px 1px rgba(0,0,0,.1);
&.active {
background: #7ca7f8;
}
}
}
```

` ````
// Up to which number would you like to see the preceding primes?
let limit = 1000;
let SELECTORS = {
grid: '.tdc-grid',
grid_item: 'tdc-grid-item'
}
let CLASSES = {
active: 'active'
}
/*
* Return a list of primes (or non_primes) up to a certain limit
*/
let sieve = (lim) => {
let primes = [];
let non_primes = [];
for(let number = 2; number < Math.sqrt(lim); number++) {
if(!_.contains(non_primes, number)) {
for(let unmarked = Math.pow(number, 2); unmarked < lim; unmarked += number) {
non_primes.push(unmarked);
}
}
}
non_primes = _.sortBy(_.uniq(non_primes), n => n);
return _.filter(_.range(2, lim), n => !_.contains(non_primes, n));
};
/*
* Draw as many grid items as set in the parameters
*/
let drawGrid = (lim) => {
_.each(_.range(2, lim), number => {
$(SELECTORS.grid).append(`<div class="${SELECTORS.grid_item} number-${number}"> ${number} </div>`);
});
};
/*
* Give each prime number an active class to distinguish
*/
let drawPrimes = (primes) => {
_.each(primes, prime => {
$(`.number-${prime}`).addClass(CLASSES.active);
});
};
drawGrid(limit);
drawPrimes(sieve(limit));
```

999px

Loading
..................

Alt F
Opt F
Find & Replace

Also see: Tab Triggers