Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
week 6 hw
- Loading branch information
Showing
3 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Object-Orientented JS</title> | ||
</head> | ||
<body> | ||
<script> | ||
function Person(first, last, age, gender, interests) { | ||
this.name = { | ||
first : first, | ||
last : last | ||
}; | ||
this.age = age; | ||
this.gender = gender; | ||
this.interests = interests; | ||
this.bio = function() { | ||
alert(this.name.first + ' ' + this.name.last + ' is ' + this.age + ' years old. He likes ' + this.interests[0] + ' and ' + this.interests[1] + '.'); | ||
}; | ||
this.greeting = function() { | ||
alert('Hi! I\'m ' + this.name.first + '.'); | ||
}; | ||
} | ||
let person1 = new Person('Bob', 'Smith', 32, 'male', ['music', 'skiing']); | ||
|
||
|
||
|
||
|
||
</script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Reversing an Array</title> | ||
</head> | ||
<body> | ||
<script> | ||
|
||
function reverseArray(input){ | ||
var output = []; | ||
for (i = 0; i < input.length; i++){ | ||
output.unshift(input[i]); | ||
} | ||
return output; | ||
} | ||
|
||
function reverseArrayInPlace(input){ | ||
for (i = 1; i < input.length; i++){ | ||
var remove = input.splice(i,1) | ||
input.unshift(remove[0]); | ||
} | ||
return input; | ||
} | ||
|
||
|
||
console.log(reverseArray(["A", "B", "C"])); | ||
// → ["C", "B", "A"]; | ||
console.log(reverseArrayInPlace([1, 2, 3, 4, 5])); | ||
// → [5, 4, 3, 2, 1] | ||
console.log(reverseArrayInPlace([1, 2, 3, 4, 5, 6])); | ||
// → [6, 5, 4, 3, 2, 1] | ||
</script> | ||
</body> | ||
</html> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Sum of a Range</title> | ||
</head> | ||
<body> | ||
|
||
<script> | ||
|
||
function range( start, end, increment ) { | ||
|
||
var result = []; | ||
if ( increment == undefined ) | ||
increment = 1; | ||
|
||
numLoops = Math.abs( (end - start)/ increment ) + 1 ; | ||
|
||
for ( var i = 0; i < numLoops; i ++ ) { | ||
|
||
result.push( start ); | ||
|
||
start += increment; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
function sum( numArray ) { | ||
|
||
var arrayTotal = 0; | ||
|
||
|
||
numLoops = numArray.length; | ||
|
||
|
||
for ( var i = 0; i < numLoops; i ++ ) { | ||
|
||
arrayTotal += numArray[i]; | ||
} | ||
|
||
return arrayTotal; | ||
} | ||
|
||
console.log(range(1, 10)); | ||
// → [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
console.log(range(5, 2, -1)); | ||
// → [5, 4, 3, 2] | ||
console.log(sum(range(1, 10))); | ||
// → 55 | ||
</script> | ||
</body> | ||
</html> |