Skip to content

Instantly share code, notes, and snippets.

@marcmoore
Last active November 17, 2015 09:13
Show Gist options
  • Save marcmoore/086f6c39d856a38b9ffb to your computer and use it in GitHub Desktop.
Save marcmoore/086f6c39d856a38b9ffb to your computer and use it in GitHub Desktop.

Q1: Try to understand what's the perpose of this paragraph of code. And fix it.

<!doctype html>
<title></title>
<meta charset="utf-8"/>
<script type="text/javascript">
  window.onload = function(){
     for(var i=1; i < 4; i++){
        var id = document.getElementById("a" + i);
           id.onclick = function(){
                 alert(i);
           }
     }
  }
</script>
<ul>
  <li id="a1">aa</li>
  <li id="a2">aa</li>
  <li id="a3">aa</li>
</ul>

Q2: What’s the value of 'result'?

var result = “hello, world!”.replace(“o”,”i”);

Q3: What’s the output?

var foo = “hello”;
function fxn(){
    alert(foo);
    var foo = “bye”;
}
fxn();
alert(foo);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment