Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- WDI Week 2 Assessment
- 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:
- button.createElement("button");
- or else 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.addClassName("clicked");
- (or is this question looking for CSS?)
- # Write code that will give the button a click handler and log 'hello'
- # to the console when it is clicked:
- button.addEventListener("onclick", function() {
- 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.addEventListener("onlick", function() {
- console.log(this.button);
- });
- # If you type 'this' straight into the console, you will get an object called
- # Window. Explain in one sentence what this object is:
- "This" references the current area you're in - in the global scope, within a given function, etc.
- A generic "this" not nested under a function/conditional/something else that manipulates the document flow
- is located in the global scope, available to the full browser 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 (writeDing(), 3000);
- Write your answer here:
- setTimeout(writeDing() {
- console.log("Ding!");
- } 3000);
- 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]);
- *** Not sure what I was doing below - other than looping through the array - but perhaps it's relevant?
- for (i = 0; i < gameOfThrones.length; i++) {
- console.log(gameOfThrones[i]);
- }
- for (j = 0; j < gameOfThrones[i].length; j++) {
- console.log(gameOfThrones[i][j]);
- }
- 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":
- gameOfThrones: greyjoy[1] = "Reek";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement