Last active
September 27, 2017 07:16
-
-
Save nvandoorn/389e0f7b02ed388b14d24f73963dacfa to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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