Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
added wk 6
  • Loading branch information
maa17019 committed Mar 1, 2021
1 parent 5d28269 commit 717e9e6
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
Binary file added week-6/.DS_Store
Binary file not shown.
31 changes: 31 additions & 0 deletions week-6/mdn-object-oriented-js/index.html
@@ -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>
37 changes: 37 additions & 0 deletions week-6/reversing-an-array/index.html
@@ -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>
39 changes: 39 additions & 0 deletions week-6/sum-of-a-range/index.html
@@ -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>

0 comments on commit 717e9e6

Please sign in to comment.