Quick Random Value
copy console.log ( [ 'x' , 'y' , 'z' ] [ Math .floor ( Math .random ( ) * 3 ) ] ) ;
Try it out…
This will output either x, y
or z
. It works by looking up a random index of an inline array. I find this great for quick prototyping – probably not something you want to be using outside throw away code… Hit the “Try it out…” button and open your dev console.
Editible Div With Memory (localStorage)
copy const el = document.createElement ( 'div' ) el.innerHTML = localStorage.memory == null ? 'type here' : localStorage.memory el.contentEditable = true ; document.body .appendChild ( el) ; document.addEventListener ( 'keyup' , ( ) => { localStorage.memory = el.innerHTML ; } ) ;
Try it out
Create an editable div that remembers what was typed in it.
createElement and Object.assign
copy const el = document.createElement ( 'div' ) ; Object .assign ( el.style , { position: 'absolute' , left: '100px' , top: '100px' , width: '30px' , height: '30px' , background: 'linear-gradient(black, red)' , transform: 'rotate(15deg)' } ) ; document.body .appendChild ( el) ;
Try it out…
Fast and easy way to set many styles on a DOM node. Click/tap the “Try it out” button to play around with the code.