Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,17 @@ Your objectives for the day is to:

### Scopes

- [ ] Watch these videos on Type and Scope
- [x] Watch these videos on Type and Scope
- https://shereef.wistia.com/medias/mlnjxm9z9s
- https://shereef.wistia.com/medias/hn99v12lkr
- https://shereef.wistia.com/medias/6snmj6es7v
- https://shereef.wistia.com/medias/5bva01dxbw
- [ ] Signup for [Udacity Object Oriented Javascript][udacity]
- [ ] Complete the [Scopes lesson][udacity]
- [x] Signup for [Udacity Object Oriented Javascript][udacity]
- [x] Complete the [Scopes lesson][udacity]

### Closures

- [ ] Complete the [Closures lesson][udacity]
- [x] Complete the [Closures lesson][udacity]

## Day 2: Objects and "this"

Expand Down
39 changes: 39 additions & 0 deletions day_2/getters_setters.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Object Oriented JavaScript</title>
</head>
<body>
<script type="text/Javascript">

var address = {
street: "No Street",
city: "No City",
state: "No State",

get getAddress(){
return this.street + " , " + this.city + " , " + this.state;
},

set setAddress(theAddress){
var parts = theAddress.toString().split(", ");
this.street = parts [0] || "";
this.city = parts [1] || "";
this.state = parts [2] || "";
}
}

address.setAddress = "123 main St, Pittsburgh, PA";

document.write("Address : " + address.getAddress + "<br />");

document.write("City : " + address.city + "<br />");

// this is the output
// Address : 123 main St , Pittsburgh , PA
// City : Pittsburgh

</script>
</body>
</html>
34 changes: 34 additions & 0 deletions day_2/objects.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Object Oriented JavaScript</title>
</head>
<body>
<script type="text/Javascript">

function getSum(num1, num2){
return num1 + num2
}
document.write("num of arguments " + getSum.length + "<br />");

function Mammal(name){
this.name = name;
this.getInfo = function(){
return "The mammals name is " + this.name;
}
}
Mammal.prototype.sound = "Grrrr";

Mammal.prototype.makeSound = function(){
return this.name + " says " + this.sound;
}

var grover = new Mammal("Grover");

document.write(grover.makeSound() + "<br />")
for

</script>
</body>
</html>
42 changes: 42 additions & 0 deletions day_2/privateProperties.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Object Oriented JavaScript</title>
</head>
<body>
<script type="text/Javascript">

function SecretCode(){
var secretNum = 78;

this.guessNum = function(num){
if(num > 78){
return "lower";
}else if (num < 78){
return "higher";
}else {
return "you guessed it!";
}
}
}

var secret = new SecretCode();

document.write("Is 73 the number : " + secret.guessNum(73) + "<br />");

document.write("Is 78 the number : " + secret.guessNum(78) + "<br />");

SecretCode.prototype.getSecret = function(){
return this.secretNum;
}

document.write("The secret number is " + secret.getSecret() + "<br />");





</script>
</body>
</html>
60 changes: 60 additions & 0 deletions day_2/prototypes.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Object Oriented JavaScript</title>
</head>
<body>
<script type="text/Javascript">

function getSum(num1, num2){
return num1 + num2
}
document.write("num of arguments " + getSum.length + "<br />");

function Mammal(name){
this.name = name;
this.getInfo = function(){
return "The mammals name is " + this.name;
}
}
Mammal.prototype.sound = "Grrrr";

Mammal.prototype.makeSound = function(){
return this.name + " says " + this.sound;
}

var grover = new Mammal("Grover");

document.write(grover.makeSound() + "<br />")

for(var prop in grover){
document.write(prop + " : " + grover[prop] + "<br />");
}

document.write("name Property of grover : " + grover.hasOwnProperty("name") + "<br />");

document.write("sound Property of grover : " + grover.hasOwnProperty("sound") + "<br />");

Array.prototype.inArray = function inArray(value){
for (var i = 0; i < this.length; i++){
if(this[i]=== value){
return true;
}
}
return false;
}

var sampArray = [1,2,3,4,5];

document.write("3 in array " + sampArray.inArray(3) + "<br />")







</script>
</body>
</html>