Skip to content

Instantly share code, notes, and snippets.

@owenso
Last active August 29, 2015 14:23
Show Gist options
  • Save owenso/b6d5419124b84e681033 to your computer and use it in GitHub Desktop.
Save owenso/b6d5419124b84e681033 to your computer and use it in GitHub Desktop.
WK 02 Assessment - Owens O'Brien
// Using a Constructor Function, create a Cupcake Constructor.
// Question 5 / 6 - Write your Cupcake Constructor Function here.
var Cupcake = function (cakeFlavor, frostingFlavor){
this.cake = cakeFlavor;
this.frostingFlavor = frostingFlavor;
this.sprinkles = false;
this.getCake = function (){
return this.cake;
}
this.getFrosting = function(){
return this.frostingFlavor;
}
this.addSprinkles = function(){
this.sprinkles = true;
}
this.hasSprinkles = function(){
return this.sprinkles
}
this.reFrost = function(newFrosting){
this.frostingFlavor = newFrosting;
}
}
window.onload = function() {
console.log('chillin in the park.');
// Question 7 - Add h1 tag to the Body
var awYeahItsParkTime = document.createElement("h1");
awYeahItsParkTime.innerHTML = "$uite Park Time"
document.body.appendChild(awYeahItsParkTime);
// Question 8 - Click Event on Duck
var quackQuackBaby = document.getElementById("duck")
quackQuackBaby.addEventListener("click", wPInTheHouse);
};
var wPInTheHouse = function(){
this.setAttribute("id", "weaselpecker")
}

Concepts

  1. What is the DOM?

The DOM or Document Object Model is an object which allows us to manipulate a webpage.

  1. Explain how an event listener function works in JavaScript.

An event listener function, when applied to something, works by "listening" for an event, and when it detects that event, executes a function that was passed in as an argument.

  1. What is a Constructor Function?

A constructor function is a function which allows us to create new objects. The constructor acts like a template, passing in keys and values to the new object, based on the arguments it has been given as well as default values established in the function.

@WilliamfShaw
Copy link

7 - straight killing it!! Good job man

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment