Advertisement
Guest User

Untitled

a guest
Oct 9th, 2015
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. 1. DOM
  2.  
  3. # Write a line of code that will create a button:
  4.  
  5. var button = document.createElement(button1);
  6.  
  7. # Write a line of code that will append that button to the document body:
  8.  
  9. document.appendChild(button1);
  10.  
  11. # Write a line of code that will give the button a class of 'clicked':
  12.  
  13. set.attribute("id", "clicked");
  14.  
  15. # Write code that will give the button a click handler and log 'hello'
  16. # to the console when it is clicked:
  17.  
  18. document.getElementByTagName("button").onclick = console.log("hello");
  19.  
  20. # Write code that will give the button a click handler and log **this** button
  21. # object to the console when it is clicked:
  22.  
  23. button.onclick = showMe
  24.  
  25. function showMe() {
  26. console.log("***this***");
  27.  
  28. # If you type 'this' straight into the console, you will get an object called
  29. # Window. Explain in one sentence what this object is:
  30.  
  31. 2. CALLBACKS
  32.  
  33. # A fellow student shows you this code. When he runs it, he expects it to
  34. # wait three seconds, then write "Ding!" to the console. Instead, it writes
  35. # "Ding!" immediately. Find the bug and fix it.
  36.  
  37. function writeDing() {
  38. console.log('Ding!');
  39. }
  40.  
  41. var dingHandle = setTimeout (writeDing(), 3000);
  42.  
  43. Write your answer here:
  44.  
  45. 3. MISC - ARRAYS AND OBJECTS
  46.  
  47. # Given the following multi-dimensional array, write the code that will log
  48. # "Eddard" to the console:
  49.  
  50. var gameOfThrones = [["Joffrey", "Stannis", "Renly"], ["Arya", "Sansa", "Eddard"]];
  51.  
  52. gameOfTrones[1][2]; = "Eddard"
  53.  
  54. # Given the following object, write the code that will log "Ramsay" to the
  55. # console:
  56.  
  57. var gameOfThrones2 = { boltons: ["Roose", "Ramsay"],
  58. greyjoys: ["Balon", "Theon"]}
  59.  
  60. console.log(gameOfThrones2[1];
  61.  
  62. # Write the code that will change "Theon" within the gameOfThrones2 object to "Reek":
  63.  
  64. I'm thinking I have to iterate over the current value "Theon" to get it to "Reek" but I am not sure how to do that.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement