Last active
October 9, 2015 13:32
-
-
Save kcooper22/f9c578db293ee35c59e4 to your computer and use it in GitHub Desktop.
Kyle Cooper WDI Week 2 Assessment
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
Congratulations on your second week of WDI! | |
To help us track your progress from the last week, please answer the following questions to the best of your ability: | |
1. DOM | |
# Write a line of code that will create a button: | |
var button = document.createElement('button); | |
# Write a line of code that will append that button to the document body: | |
body.appendChild(button); | |
# Write a line of code that will give the button a class of 'clicked': | |
button.setAttribute('class','clicked); | |
# Write code that will give the button a click handler and log 'hello' | |
# to the console when it is clicked: | |
button.onclick = function(event){ | |
console.log("hello"); | |
} | |
# Write code that will give the button a click handler and log **this** button | |
# object to the console when it is clicked: | |
button.onclick = function(event){ | |
console.log(this); | |
} | |
# If you type 'this' straight into the console, you will get an object called | |
# Window. Explain in one sentence what this object is: | |
'this' refers to the object it is being called in, so when called inside of the console this is only inside of the window. | |
2. CALLBACKS | |
# A fellow student shows you this code. When he runs it, he expects it to | |
# wait three seconds, then write "Ding!" to the console. Instead, it writes | |
# "Ding!" immediately. Find the bug and fix it. | |
function writeDing() { | |
console.log('Ding!'); | |
} | |
var dingHandle = setTimeout(function(){ (writeDing(); | |
}, 3000); | |
Write your answer here: | |
3. MISC - ARRAYS AND OBJECTS | |
# Given the following multi-dimensional array, write the code that will log | |
# "Eddard" to the console: | |
var gameOfThrones = [["Joffrey", "Stannis", "Renly"], ["Arya", "Sansa", "Eddard"]]; | |
console.log(gameOfThrones[1][2]; | |
# Given the following object, write the code that will log "Ramsay" to the | |
# console: | |
var gameOfThrones2 = { boltons: ["Roose", "Ramsay"], | |
greyjoys: ["Balon", "Theon"]} | |
console.log(gameOfThrones2.boltons[1]); | |
# Write the code that will change "Theon" within the gameOfThrones2 object to "Reek": | |
gameOfThrones2.greyjoys[1] = "Reek"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment