Last active
October 9, 2015 06:18
-
-
Save jdlrobson/3452890 to your computer and use it in GitHub Desktop.
This is bad code. Tell me why.
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
<!DOCTYPE HTML> | |
<html> | |
<body> | |
<ul id="list1"> | |
<li><span>apple</span></li> | |
<li><span>banana</span></li> | |
<li id="last"><span>carrot</span></li> | |
</ul> | |
<script type="text/javascript"> | |
// given a parent | |
function punctuate( parent, questionmarkflag ) { | |
var text = typeof( questionmarkflag ) !== 'undefined' ? '???' : '!!!'; | |
var lastItem = document.querySelectorAll( '#last' )[ 0 ]; | |
var items = parent.getElementsByTagName( 'span' ); | |
for( var i = 0; i < items.length; i++ ) { | |
el = document.createElement("span") | |
el.innerText = text; | |
items[ i ].appendChild(el ); | |
} | |
if( items.length > 0 ) lastItem.className = 'finished'; | |
} | |
punctuate( document.getElementById( 'list1' ) ); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment