Skip to content

Instantly share code, notes, and snippets.

@ThomasBurleson
Forked from s4nchez/js_test.html
Created February 28, 2012 02:52
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 ThomasBurleson/1928977 to your computer and use it in GitHub Desktop.
Save ThomasBurleson/1928977 to your computer and use it in GitHub Desktop.
Basic JavaScript skills test
<html>
<head></head>
<body>
<input name="myButton" type="button" value="button 1">
<input name="myButton" type="button" value="button 2">
<input name="myButton" type="button" value="button 3">
<script type="text/javascript">
var buttons = document.getElementsByName("myButton");
for(var i = 0; i < buttons.length; i++){
buttons[i].onclick = function(){
window.alert("clicked button " + (i + 1));
};
}
</script>
</body>
</html>
@ThomasBurleson
Copy link
Author

Questions to ask candidates:

What do the alerts show ?
Why does that happen ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment