Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
5153f04
exercise-1 done
Gautham-Apxor Apr 4, 2023
6794500
exercise-2 done
Gautham-Apxor Apr 4, 2023
99efa8c
exercise-3 done
Gautham-Apxor Apr 4, 2023
3a09680
exercise-4 done
Gautham-Apxor Apr 4, 2023
e27b1af
exercise-5 done
Gautham-Apxor Apr 4, 2023
6ff17a8
exercise-6 done
Gautham-Apxor Apr 4, 2023
72becb8
exercise-7 done
Gautham-Apxor Apr 4, 2023
7a6fc25
exercise-8 done
Gautham-Apxor Apr 4, 2023
cf18004
exercise-9 done
Gautham-Apxor Apr 4, 2023
73b58e1
exercise-10 done
Gautham-Apxor Apr 4, 2023
7b42295
exercise-11 done
Gautham-Apxor Apr 4, 2023
77a70e6
exercise-12 done
Gautham-Apxor Apr 4, 2023
934b24e
exercise-13 done
Gautham-Apxor Apr 4, 2023
108f385
exercise-14 done
Gautham-Apxor Apr 4, 2023
b371498
exercise-15 done
Gautham-Apxor Apr 4, 2023
ef7b201
exercise-16 done
Gautham-Apxor Apr 5, 2023
2d6f908
exercise-17 done
Gautham-Apxor Apr 5, 2023
37aded2
exercise-18 done
Gautham-Apxor Apr 5, 2023
0a3395d
exercise-19 done
Gautham-Apxor Apr 6, 2023
e916538
exercise-20 done
Gautham-Apxor Apr 6, 2023
95f5b6a
exercise-21 done
Gautham-Apxor Apr 6, 2023
80e41bf
exercise-22 done
Gautham-Apxor Apr 6, 2023
f43bc2f
exercise-23 done
Gautham-Apxor Apr 6, 2023
aeaccbd
exercise-24 done
Gautham-Apxor Apr 6, 2023
e98dc2f
exercise-25 done
Gautham-Apxor Apr 6, 2023
84b611f
exercise-26 done
Gautham-Apxor Apr 6, 2023
8600471
exercise-27 done
Gautham-Apxor Apr 6, 2023
c712883
exercise-28 done
Gautham-Apxor Apr 6, 2023
18350df
exercise-29 done
Gautham-Apxor Apr 6, 2023
e6fc4a6
exercise-30 done
Gautham-Apxor Apr 6, 2023
bf49d77
exercise-31 done
Gautham-Apxor Apr 6, 2023
7cd64a6
exercise-32 done
Gautham-Apxor Apr 6, 2023
cb2736d
exercise-33 done
Gautham-Apxor Apr 6, 2023
78fce6c
exercise-34 done
Gautham-Apxor Apr 6, 2023
bc15432
exercise-35 done
Gautham-Apxor Apr 6, 2023
ca3caac
exercise-36 done
Gautham-Apxor Apr 6, 2023
12ba3c0
exercise-37 done
Gautham-Apxor Apr 8, 2023
ec198ba
modified exercise-6
Gautham-Apxor Apr 8, 2023
9a3ccd8
modified exercise-8
Gautham-Apxor Apr 8, 2023
8127fa7
modified exercise-14
Gautham-Apxor Apr 8, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/exercises/1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
// - Fix the issue.

function printOneToTen() {
for (const number = 1; number <= 10; number++) {
console.log(`\n${number}`);
let x = [];
for (let number = 1; number <= 10; number++) {
// Variables defined with const cannot be Reassigned
//console.log(`\n${number}`);
x.push(number);
}
return x;
}
module.exports = printOneToTen;
5 changes: 5 additions & 0 deletions src/exercises/1/exercise1.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const printOneToTen = require('./exercise.js');

test('print one to ten', () => {
expect(printOneToTen()).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
});
6 changes: 5 additions & 1 deletion src/exercises/10/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,8 @@
}
]
*/
function findVoteEligibleCandidates(populationList) {}
function findVoteEligibleCandidates(populationList) {
console.log(`${populationList.filter((element) => element.age >= 18).map((element) => element.name)}`);
}

module.exports = findVoteEligibleCandidates;
9 changes: 9 additions & 0 deletions src/exercises/10/exercise10.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
const findVoteEligibleCandidates = require('./exercise.js');

test('find vote eligible candidates', () => {
const consolepass = jest.spyOn(console, 'log');
findVoteEligibleCandidates([10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100]);
expect(consolepass).toHaveBeenCalledWith(`${[10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100].filter((element) => element.age >= 18).map((element) => element.name)}`);
findVoteEligibleCandidates([1, 12, 14]);
expect(consolepass).toHaveBeenCalledWith(`${[1, 12, 14].filter((element) => element.age >= 18).map((element) => element.name)}`);
});
4 changes: 3 additions & 1 deletion src/exercises/11/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
// - Use Array methods
// - Do not use loops

function sumOfArray(inputArray) {}
function sumOfArray(inputArray) {
return `${inputArray.reduce((total, value) => total + value)}`;
}
9 changes: 7 additions & 2 deletions src/exercises/12/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,10 @@ function errorFunction() {
}

function errorCaller() {
errorFunction();
}
try {
errorFunction();
}
catch (error) {
console.log(error);
}
}
12 changes: 10 additions & 2 deletions src/exercises/13/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ const employee = {
lastName: "Teja",
age: 29,
id: 1122,
getFullName: function () {},
checkVoteEligiblity: function () {},
getFullName: function () {
return this.firstName + " " + this.lastName;
},
checkVoteEligiblity: function () {
if (this.age >= 18) {
return "Eligible";
} else {
return "Not Eligible";
}
},
};
9 changes: 9 additions & 0 deletions src/exercises/14/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,19 @@ const employee = {
id: 1122,
getFullName: function () {
//Copy the solution from the exercise before this.
return this.firstName + " " + this.lastName;
},
};

const newEmployee = {
firstName: "New",
lastName: "Employee",
getFullName: employee.getFullName,
// or in place of getFullName: employee.getFullName,
// you can also write getFullName: employee.getFullName.bind(newEmployee)
/* or in place of getFullName: employee.getFullName, this can also be done
__proto__: employee
*/
};

//const getFullName = employee.getFullName.call(newEmployee); //This is one of the way it can be done.
6 changes: 2 additions & 4 deletions src/exercises/15/exercise.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// Convert the below functions into arrow functions.

const greetings = function () {
return "Hello World";
};
const greetings = () => "Hello World";

const isEven = function (num) {
const isEven = (num) => {
if (num % 2 == 0) {
return true;
} else {
Expand Down
47 changes: 46 additions & 1 deletion src/exercises/16/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,51 @@
// - Identify the class variables
// - Create function for all the possible functionalities.

class Leave {
export class Leave {
//...
constructor(leaveType, leaveStartDate, leaveEndDate) {
//...
this._leaveType = leaveType;
this._leaveStartDate = leaveStartDate;
this._leaveEndDate = leaveEndDate;
this._leaveDays = this.calculateLeaveDays();
}

get leaveType() {
return this._leaveType;
}

get leaveStartDate() {
return this._leaveStartDate;
}

get leaveEndDate() {
return this._leaveEndDate;
}

set leaveType(leaveType) {
this._leaveType = leaveType;
}

set leaveStartDate(leaveStartDate) {
this._leaveStartDate = leaveStartDate;
}

set leaveEndDate(leaveEndDate) {
this._leaveEndDate = leaveEndDate;
}

calculateLeaveDays() {
//...
return this._leaveEndDate - this._leaveStartDate;
}

approveLeave() {
//...
if (this._leaveDays > 5) {
console.log("Leave Rejected");
} else {
console.log("Leave approved");
}
}
}
44 changes: 44 additions & 0 deletions src/exercises/17/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,45 @@
// Extend the Leave class, to create different classes for different Leave types.
import { Leave } from "../16/exercise.js";
class SickLeave extends Leave {
constructor(leaveStartDate, leaveEndDate) {
super("Sick", leaveStartDate, leaveEndDate);
this.limit = 5;
}

approveLeave() {
if (this._leaveDays > this.limit) {
console.log("Leave Rejected");
} else {
console.log("Leave approved");
}
sickLeavesLeft(this.limit - this._leaveDays);
}

sickLeavesLeft(limit) {
this.limit = limit;
console.log("Sick leaves left: " + this.limit);
}
}

class CasualLeave extends Leave {
constructor(leaveStartDate, leaveEndDate) {
super("Casual", leaveStartDate, leaveEndDate);
this.limit = 10;
}

approveLeave() {
if (this._leaveDays > this.limit) {
console.log("Leave Rejected");
} else {
console.log("Leave approved");
}
casuaLeavesLeft(this.limit - this._leaveDays);
}

casuaLeavesLeft(limit) {
this.limit = limit;
console.log("Casual leaves left: " + this.limit);
}
}


21 changes: 21 additions & 0 deletions src/exercises/18/CasualLeaveClass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Leave } from "../16/exercise.js";
class CasualLeave extends Leave {
constructor(leaveStartDate, leaveEndDate) {
super("Casual", leaveStartDate, leaveEndDate);
this.limit = 10;
}

approveLeave() {
if (this._leaveDays > this.limit) {
console.log("Leave Rejected");
} else {
console.log("Leave approved");
}
casuaLeavesLeft(this.limit - this._leaveDays);
}

casuaLeavesLeft(limit) {
this.limit = limit;
console.log("Casual leaves left: " + this.limit);
}
}
21 changes: 21 additions & 0 deletions src/exercises/18/SickLeaveClass.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Leave } from "../16/exercise.js";
class SickLeave extends Leave {
constructor(leaveStartDate, leaveEndDate) {
super("Sick", leaveStartDate, leaveEndDate);
this.limit = 5;
}

approveLeave() {
if (this._leaveDays > this.limit) {
console.log("Leave Rejected");
} else {
console.log("Leave approved");
}
sickLeavesLeft(this.limit - this._leaveDays);
}

sickLeavesLeft(limit) {
this.limit = limit;
console.log("Sick leaves left: " + this.limit);
}
}
10 changes: 10 additions & 0 deletions src/exercises/18/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// Use Javascript modules to create seperate files for each of the Leave type classes.
// - Comment your understanding about import
// - Comment your understanding about export

/****Import*****/
//import allows us to import the class, functions, variables from other files and use them in the current file. Modules can be imported in two ways based on the type of export.
//The imported values are read-only views of the features that were exported. Similar to const variables, you cannot re-assign the variable that was imported, but you can still modify properties of object values. The value can only be re-assigned by the module exporting it.

/****export*****/
//export allows us to export the class, functions, variables to be used in other files.
//There are two types of exports: Named Exports and Default Exports. Named Exports are used when we have multiple things to export from a file. Default Exports are used when we have only one thing to export from a file.

//you need to include type="module" in the <script> element, to declare this script as a module. You can only use import and export statements inside modules, not regular scripts.
39 changes: 39 additions & 0 deletions src/exercises/19/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,42 @@
// Comment below what did you understand from the previous 3 exercises about
// - prototype
// - __proto__

/*********Prototype*******/
// prototype: The prototype property is used to add methods or properties to an object's prototype. The prototype is a shared property of all instances of an object created using the constructor function, and adding a method or property to it will make it available to all instances of that object. It can be used to add methods and properties to an object after it has been created.
/* // A constructor function
function Box(value) {
this.value = value;
}

// Properties all boxes created from the Box() constructor
// will have
Box.prototype.getValue = function () {
return this.value;
};

const boxes = [new Box(1), new Box(2), new Box(3)];
//Box.prototype it's just a plain object. Every instance created from a constructor function will automatically have the constructor's prototype property as its [[Prototype]] — that is, Object.getPrototypeOf(new Box()) === Box.prototype. Constructor.prototype by default has one own property: constructor, which references the constructor function itself — that is, Box.prototype.constructor === Box. This allows one to access the original constructor from any instance.
*/


/*********__proto__*******/
// __proto__: The __proto__ property is an internal property of an object that points to its prototype. It is used to access the prototype of an object, and can also be used to set the prototype of an object. When a property is accessed on an object, JavaScript first looks for the property on the object itself, and if it is not found, it looks for it in the object's prototype, and so on up the prototype chain until the property is found or the end of the prototype chain is reached.
/* const o = {
a: 1,
b: 2,
// __proto__ sets the [[Prototype]]. It's specified here
// as another object literal.
__proto__: {
b: 3,
c: 4,
__proto__: {
d: 5,
},
},
};

// { a: 1, b: 2 } ---> { b: 3, c: 4 } ---> { d: 5 } ---> Object.prototype ---> null

console.log(o.d); // 5
*/
11 changes: 8 additions & 3 deletions src/exercises/2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
// - Fix the issue.

function divideTenByNumber(number) {
//Variables defined with let have block scope. They are only accessible within the block they are defined in.
let result;
if (number != 0) {
let result = 10 / number;
result = 10 / number;
} else {
let result = "Indeterminate";
result = "Indeterminate";
}

console.log(`Result after dividing 10 by ${number} is ${result}`);
//console.log(`Result after dividing 10 by ${number} is ${result}`);
return result;
}

module.exports = divideTenByNumber;
6 changes: 6 additions & 0 deletions src/exercises/2/exercise2.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
const divideTenByNumber = require('./exercise.js');

test('divide ten by number', () => {
expect(divideTenByNumber(5)).toEqual(2);
expect(divideTenByNumber(0)).toEqual("Indeterminate");
});
19 changes: 19 additions & 0 deletions src/exercises/20/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
// What is debugger;
// - Comment your understanding of it.
// - Paste the link of the MDN article here.


// Debugger is a keyword that stops the execution of the code and allows you to inspect the current state of the code. It is useful for debugging purposes.

/*Debugging is the process of finding and fixing errors within a script.
A breakpoint is a point of code where the debugger will automatically pause the JavaScript execution.
While the code is paused, we can examine current variables, execute commands in the console etc. In other words, we can debug it.

Watch – shows current values for any expressions.(You can click the plus + and input an expression. The debugger will show its value, automatically recalculating it in the process of execution.)

Call Stack – shows the nested calls chain.

Scope – current variables.
Local shows local function variables. You can also see their values highlighted right over the source.
Global has global variables (out of any functions).

*/

// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger
7 changes: 7 additions & 0 deletions src/exercises/21/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
// What are the different levels of logs and how do we print them to the console?

/* logs are used to debug the code. There are 4 levels of logs:
1. console.log() - used to print the output to the console.
2. console.info() - used to print the information to the console.
3. console.warn() - used to print the warning to the console.
4. console.error() - used to print the error to the console.
*/
Binary file added src/exercises/22/1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/exercises/22/2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/exercises/22/3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/exercises/22/4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/exercises/22/5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/exercises/22/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading