Skip to content

Instantly share code, notes, and snippets.

@nvandoorn
Last active September 27, 2017 07:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nvandoorn/389e0f7b02ed388b14d24f73963dacfa to your computer and use it in GitHub Desktop.
Save nvandoorn/389e0f7b02ed388b14d24f73963dacfa to your computer and use it in GitHub Desktop.
var inputBox = document.getElementById('input-box')
var btn = document.getElementById('submit-input-box')
var showValues = document.getElementById('show-values')
btn.addEventListener('click', function () {
var text = inputBox.value
var tokens = text.split(',').map(k => k.trim()) // this removes whitespace from each token
// you could also do this with a for loop and remove the map() as follows
// for(var token of tokens) {
// token = token.trim()
// }
tokens.sort()
showValues.innerHTML = '' // clears list
// clear list by setting empty inner HTML
for(var token of tokens) { // token is current value
var toAppend = document.createElement('li') // making empty <li>
toAppend.innerText = token // filling in text for <li>value of token here</li>
showValues.appendChild(toAppend) // appending to the bottom of <ol>
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment