Created
May 26, 2015 13:05
-
-
Save chadsansing/ff00e262c0d462f7cba0 to your computer and use it in GitHub Desktop.
Example of OOP for class
This file contains hidden or 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
<!doctype html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<script> | |
function randomObject() { | |
function Dessert(name, taste, texture) { | |
this.name = name; | |
this.taste = taste; | |
this.texture = texture; | |
} | |
var chocolatePudding = new Dessert("Chocolate pudding", "rich", "gooey"); | |
var cheeseCake = new Dessert("Cheese cake", "tart", "smooth"); | |
var oatmealRaisinCookies = new Dessert("Oatmeal-raisin cookies", "sweet", "chewy"); | |
var desserts = [chocolatePudding, cheeseCake, oatmealRaisinCookies]; | |
this.desserts = desserts[Math.random(Math.round()*(desserts.length-1))]; | |
this.getDessertsName = this.desserts.name; | |
this.getDessertsTaste = this.desserts.taste; | |
this.getDessertsTexture = this.desserts.texture; | |
document.getElementById("myObject").innerHTML = "<div>" + this.getDessertsName + " is/are " + this.getDessertsTaste + " and " + this.getDessertsTexture + ".</div>" | |
} | |
</script> | |
</head> | |
<body> | |
<p><button onClick="randomObject()">Click me!</button></p> | |
<div id="myObject"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment