Changed code from document.write to console.log, to work with JS Fiddle.