var primeChecker = {
/**
* Memoize our previously hit primes
*/
cache: {},
/**
* Cached DOM selectors
*/
selectors: {
mainContainer: document.getElementById('main-container'),
inputLabel: document.getElementById('js-prime-input'),
input: document.getElementById('js-prime-input'),
submitBtn: document.getElementById('js-prime-check'),
errorContainer: document.getElementById('error-container'),
primeResultsContainer: document.getElementById('prime-results'),
recursiveCheckbox: document.getElementById('recursive-checkbox')
},
/**
* Append all successfully found primes to the container
*/
appendResults: function (primes) {
var toAppend = primes.join(' <p></p> *'),
resultsContainer = this.selectors.primeResultsContainer;
resultsContainer.style.display = 'block';
resultsContainer.innerHTML = '*' + toAppend;
},
/**
* Attach event listener for the click action of the "Get primes!" button
*/
attachEventListeners: function () {
var CLICK = 'click',
self = this,
primeCheckBtn = this.selectors.submitBtn,
handleEventAction = function (evt) {
evt.preventDefault();
// Need to maintain context to `this` so we'll use call here
self.handleSubmit.call(self, evt);
};
primeCheckBtn.addEventListener(CLICK, handleEventAction, false);
},
/**
* Remove class on main container if no hit from cache
*/
changeSignToDefault: function () {
var mainContainer = this.selectors.mainContainer;
mainContainer.className = '';
},
/**
* Add class to main container to change background position if
* we got a hit from our cache
*/
changeSignToRed: function () {
var mainContainer = this.selectors.mainContainer;
mainContainer.className +=...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.