Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 KB | None | 0 0
  1. WDI Week 2 Assessment
  2. Congratulations on your second week of WDI!
  3.  
  4. To help us track your progress from the last week, please answer the following questions to the best of your ability:
  5.  
  6. 1. DOM
  7.  
  8. # Write a line of code that will create a button:
  9. button.createElement("button");
  10. or else button.document.createElement("button") ?
  11.  
  12. # Write a line of code that will append that button to the document body:
  13. body.appendChild("button");
  14.  
  15. # Write a line of code that will give the button a class of 'clicked':
  16. button.addClassName("clicked");
  17. (or is this question looking for CSS?)
  18.  
  19. # Write code that will give the button a click handler and log 'hello'
  20. # to the console when it is clicked:
  21. button.addEventListener("onclick", function() {
  22. console.log("hello;");
  23. });
  24.  
  25. # Write code that will give the button a click handler and log **this** button
  26. # object to the console when it is clicked:
  27. button.addEventListener("onlick", function() {
  28. console.log(this.button);
  29. });
  30.  
  31. # If you type 'this' straight into the console, you will get an object called
  32. # Window. Explain in one sentence what this object is:
  33. "This" references the current area you're in - in the global scope, within a given function, etc.
  34. A generic "this" not nested under a function/conditional/something else that manipulates the document flow
  35. is located in the global scope, available to the full browser window.
  36.  
  37. 2. CALLBACKS
  38.  
  39. # A fellow student shows you this code. When he runs it, he expects it to
  40. # wait three seconds, then write "Ding!" to the console. Instead, it writes
  41. # "Ding!" immediately. Find the bug and fix it.
  42.  
  43. function writeDing() {
  44. console.log('Ding!');
  45. }
  46.  
  47. var dingHandle = setTimeout (writeDing(), 3000);
  48.  
  49. Write your answer here:
  50.  
  51. setTimeout(writeDing() {
  52. console.log("Ding!");
  53. } 3000);
  54.  
  55. 3. MISC - ARRAYS AND OBJECTS
  56.  
  57. # Given the following multi-dimensional array, write the code that will log
  58. # "Eddard" to the console:
  59.  
  60. var gameOfThrones = [["Joffrey", "Stannis", "Renly"], ["Arya", "Sansa", "Eddard"]];
  61.  
  62. console.log(gameOfThrones[1][2]);
  63.  
  64. *** Not sure what I was doing below - other than looping through the array - but perhaps it's relevant?
  65. for (i = 0; i < gameOfThrones.length; i++) {
  66. console.log(gameOfThrones[i]);
  67. }
  68.  
  69. for (j = 0; j < gameOfThrones[i].length; j++) {
  70. console.log(gameOfThrones[i][j]);
  71. }
  72.  
  73. console.log(gameOfThrones[1][2]);
  74.  
  75. # Given the following object, write the code that will log "Ramsay" to the
  76. # console:
  77.  
  78. var gameOfThrones2 = { boltons: ["Roose", "Ramsay"],
  79. greyjoys: ["Balon", "Theon"]}
  80.  
  81. console.log(gameOfThrones2: boltons[1]);
  82.  
  83. # Write the code that will change "Theon" within the gameOfThrones2 object to "Reek":
  84.  
  85. gameOfThrones: greyjoy[1] = "Reek";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement