Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Eloquent JS Exercises + MDN Object Tutorial
  • Loading branch information
plb18001 committed Feb 27, 2022
1 parent b8bcfc2 commit bb11685
Show file tree
Hide file tree
Showing 6 changed files with 162 additions and 0 deletions.
15 changes: 15 additions & 0 deletions week-6/EJS-Exercises/reversing-array/index.html
@@ -0,0 +1,15 @@
<!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>
<h1>Hello Press F12 For Solution</h1>


<script src="main.js"></script>
</body>
</html>
26 changes: 26 additions & 0 deletions week-6/EJS-Exercises/reversing-array/main.js
@@ -0,0 +1,26 @@
function reverseArray(array) {
empty = [];
for(let rev of array) {
empty.unshift(rev);
}
return empty;
}

function reverseArrayInPlace(array){
for (i = 0; i < Math.floor(array.length / 2); i++){
// loops the array from 0 to the half of the array (rounded to lower number), increases i by one each time.
var old = array[i];
//temporarely stores the current value of the array at the position i in the variable old.
array[i] = array[array.length - 1 - i];
//sets the value of the i position to the value of the last element of the array minus the current i.
array[array.length - 1 - i] = old;
//sets the value of the last element of the array minus the current i to the previous value (stored in the old variable).
}
}

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]
15 changes: 15 additions & 0 deletions week-6/EJS-Exercises/sum-of-range/index.html
@@ -0,0 +1,15 @@
<!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 Range</title>
</head>
<body>
<h1>Hello Press F12 For Solution</h1>


<script src="main.js"></script>
</body>
</html>
33 changes: 33 additions & 0 deletions week-6/EJS-Exercises/sum-of-range/main.js
@@ -0,0 +1,33 @@
function range(start,end,step){
let array = [];
if (step == null){
step = 1;
}

if (start < end){
for(i = start; i <= end; i += step){
array.push(i);
}
} else {
for(k = start; k>= end; k += step){
array.push(k);
}
}
return array;
}

function sum(y) {
total = 0;
for(let x of y){
total += x;
}
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
14 changes: 14 additions & 0 deletions week-6/MDN-Object-Tutorial/index.html
@@ -0,0 +1,14 @@
<!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>
<h1>Hello There! Press F12 For the Solution</h1>

<script src="main.js"></script>
</body>
</html>
59 changes: 59 additions & 0 deletions week-6/MDN-Object-Tutorial/main.js
@@ -0,0 +1,59 @@
const person = {
name: ['Bob', 'Smith'],
age: 32,
bio() {
console.log(`${this.name[0]} ${this.name[1]} is ${this.age} years old.`);
},
introduceSelf() {
console.log(`Hi! I'm ${this.name[0]}.`);
}

};
const person1 = {
name: 'Chris',
introduceSelf() {
console.log(`Hi! I'm ${this.name}.`);
}
}

const person2 = {
name: 'Deepti',
introduceSelf() {
console.log(`Hi! I'm ${this.name}.`);
}
}

function createPerson(name) {
const obj = {};
obj.name = name;
obj.introduceSelf = function() {
console.log(`Hi! I'm ${this.name}.`);
}
return obj;
}
function Person(name) {
this.name = name;
this.introduceSelf = function() {
console.log(`Hi! I'm ${this.name}.`);
}
}

const salva = new Person('Salva');
salva.name;
salva.introduceSelf();

const frankie = new Person('Frankie');
frankie.name;
frankie.introduceSelf();

const myDiv = document.createElement('div');
const myVideo = document.querySelector('video');



const myDataName = 'height';
const myDataValue = '1.75m';
person[myDataName] = myDataValue;



0 comments on commit bb11685

Please sign in to comment.