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
added wk 6
- Loading branch information
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
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,31 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>MDN Object Tutorial</title> | ||
</head> | ||
<body> | ||
|
||
<script> | ||
function Person(first, last, age, gender, interests) { //constructor function | ||
this.name = { | ||
first: first, | ||
last: last | ||
}; | ||
this.age = age; | ||
this.gender = gender; | ||
this.interests = interests; | ||
this.bio = function() { //method | ||
alert(this.name.first + ' ' + this.name.last + ' is ' + this.age + ' years old. She likes ' + this.interests[0] + ' and ' + this.interests[1] + '.'); | ||
}; | ||
this.greeting = function() { //method | ||
alert('Hi! I\'m ' + this.name.first + '.'); | ||
}; | ||
} | ||
|
||
let person1 = new Person("Mahnoor", "Afteb", 20, "female", ["music", "movies"]) //object | ||
</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,37 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Reversing An Array</title> | ||
</head> | ||
<body> | ||
|
||
<script> | ||
function reverseArray(array) { | ||
let output = []; | ||
for (let i = array.length - 1; i >= 0; i--) { | ||
output.push(array[i]); | ||
} | ||
return output; | ||
} | ||
|
||
function reverseArrayInPlace(array) { | ||
for (let i = 0; i < Math.floor(array.length / 2); i++) { | ||
let old = array[i]; | ||
array[i] = array[array.length - 1 - i]; | ||
array[array.length - 1 - i] = old; | ||
} | ||
return array; | ||
} | ||
|
||
console.log(reverseArray(["A", "B", "C"])); | ||
// → ["C", "B", "A"]; | ||
let arrayValue = [1, 2, 3, 4, 5]; | ||
reverseArrayInPlace(arrayValue); | ||
console.log(arrayValue); | ||
// → [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,39 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Sum of a Range</title> | ||
</head> | ||
<body> | ||
|
||
<script> | ||
function range(start, end, step = start < end ? 1 : -1) { | ||
let array = []; | ||
|
||
if (step > 0) { | ||
for (let i = start; i <= end; i += step) array.push(i); | ||
} else { | ||
for (let i = start; i >= end; i += step) array.push(i); | ||
} | ||
return array; | ||
} | ||
|
||
function sum(array) { | ||
let total = 0; | ||
for (let value of array) { | ||
total += value; | ||
} | ||
return total; | ||
} | ||
|
||
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> |