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
Eloquent JS Exercises + MDN Object Tutorial
- Loading branch information
Showing
6 changed files
with
162 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,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> |
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,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] |
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,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> |
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,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 |
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,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> |
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,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; | ||
|
||
|
||
|