Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 8 additions & 1 deletion src/exercises/1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@
// - Fix the issue.

function printOneToTen() {
for (const number = 1; number <= 10; number++) {
// Error : we can't change const variable in js
// for (const number = 1; number <= 10; number++) {

// Fix: change const to let
for (let number = 1; number <= 10; number++) {
console.log(`\n${number}`);
}
}

// we need to call the function to get the Output.
printOneToTen()
27 changes: 26 additions & 1 deletion src/exercises/10/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,29 @@
}
]
*/
function findVoteEligibleCandidates(populationList) {}
function findVoteEligibleCandidates(populationList) {
console.log(populationList.filter((entry) => entry.age >= 18).map((entry => entry.name)))

// it can also be done as follow:
// console.log(populationList.forEach((entry) => {
// entry.age >= 18 ? console.log(entry.name) : null
// }))

// NOTE: filter and map returns the list. whereas, forEach doesn't return anything.
// if we need to save the result we can use filter/map not foreach
}

findVoteEligibleCandidates([
{
name:"Ravi",
age:28
},
{
name:"Teja",
age:18
},
{
name:"Spider-man",
age:17
}
])
10 changes: 9 additions & 1 deletion src/exercises/11/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@
// - Use Array methods
// - Do not use loops

function sumOfArray(inputArray) {}
function sumOfArray(inputArray) {
let sum = 0;
inputArray.forEach(element => {
sum += element;
});
console.log(sum);
}

sumOfArray([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
9 changes: 8 additions & 1 deletion src/exercises/12/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,12 @@ function errorFunction() {
}

function errorCaller() {
errorFunction();
try {
errorFunction();
}
catch(e) {
console.log(e);
}
}

errorCaller();
13 changes: 11 additions & 2 deletions src/exercises/13/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ const employee = {
lastName: "Teja",
age: 29,
id: 1122,
getFullName: function () {},
checkVoteEligiblity: function () {},
getFullName: function () {
return `${this.firstName} ${this.lastName}`;
},
checkVoteEligiblity: function () {
return this.age >= 18;
},
};



console.log(employee.getFullName());
console.log(employee.checkVoteEligiblity());
13 changes: 11 additions & 2 deletions src/exercises/14/exercise.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
// Get the full name of the new employee. See how you can execute the function "getFullName" on newEmployee object.
// - Comment your findings
// // - Comment your findings

const employee = {
firstName: "Ravi",
lastName: "Teja",
age: 29,
id: 1122,
getFullName: function () {
//Copy the solution from the exercise before this.
//Copy the solution from the exercise before this.
if(arguments.length > 0) {
return `${arguments[0].firstName} ${arguments[0].lastName}`;
}
else {
return `${this.firstName} ${this.lastName}`;
}
},
};

const newEmployee = {
firstName: "New",
lastName: "Employee",
};

console.log(employee.getFullName())
console.log(employee.getFullName(newEmployee))
7 changes: 5 additions & 2 deletions src/exercises/15/exercise.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
// Convert the below functions into arrow functions.

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

const isEven = function (num) {
const isEven = (num) => {
if (num % 2 == 0) {
return true;
} else {
return false;
}
};

console.log(greetings)
console.log(isEven)
36 changes: 35 additions & 1 deletion src/exercises/16/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,40 @@
// - Identify the class variables
// - Create function for all the possible functionalities.

class Leave {
// exporting class to be able to import in next exercise.
export class Leave {
//...
constructor(name, reason, startDate, endDate) {
this.name = name;
this.reason = reason;
this.startDate = startDate;
this.endDate = endDate ? endDate : startDate;
this.status = false;
}

showLeaveDetails() {
console.log(`---- ` + (this.status ? 'granted' : 'not yet granted') + ` ----`)
if(this.startDate === this.endDate) {
console.log(`${this.name} kept leave on ${this.startDate} for ${this.reason}.\n`);
}
else {
console.log(`${this.name} kept leave from ${this.startDate} to ${this.endDate} for ${this.reason}\n`);
}

}

grantLeave = function(){
this.status = true;
console.log(`GRANTED LEAVE TO ${this.name.toUpperCase()}\n`);
}
}

let johnLeave = new Leave("John", "marriage", "17/11/2022", "20/11/2022");
let raniLeave = new Leave("Rani", "anniversary", "18/11/2022");

johnLeave.showLeaveDetails();
raniLeave.showLeaveDetails();

johnLeave.grantLeave();

johnLeave.showLeaveDetails();
23 changes: 23 additions & 0 deletions src/exercises/17/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
// Extend the Leave class, to create different classes for different Leave types.

// imports Leave class from last exercise
import { Leave } from '../16/exercise'

class CasualLeave extends Leave {
constructor(name, startDate, endDate) {
super(name, "Holiday", startDate, endDate)
}
}


class SickLeave extends Leave {
constructor(name, startDate, endDate) {
super(name, "sick", startDate, endDate)
}
}


let johnLeave = new CasualLeave("John", "17/11/2022", "20/11/2022");
let raniLeave = new SickLeave("Rani", "18/11/2022");

johnLeave.showLeaveDetails();
raniLeave.showLeaveDetails();
11 changes: 11 additions & 0 deletions src/exercises/17/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>Hello</h1>
<script type="module" src="./exercise.js"></script>
<script type="module" src="../16/exercise.js"></script>

</body>
</html>
30 changes: 30 additions & 0 deletions src/exercises/18/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
// 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/EXPORT ::
*
* to use js import/export we need to make scripts as modules
* for this we can either use package.json({type: module}) or a HTML file(include scripts and define type="module") to define the type as 'module'
* we can export and import - functions, classes, constants etc...
* Import & Export (using index.html)
* we can do a _simple export_ lets say,
* - export class ClassName {...}
* then we can import it as
* - import { ClassName } from '../fileDirectory'
*
* for example,
* Utils.js
* export function fun1{...}
* export function fun2{...}
* Diff.js
* import {fun1, fun2} from './Utils.js'
*
*
* Or we can do default export like
* - export default class ClassName {...}
* - import ClassName from './path'
*
* Import & Export (using package.json ES-6 modules)
* module.export = { ...list }
* require('../path') -> this will return so we need to save it in a var inorder to use it( const importName = require('../path') )
*/
11 changes: 11 additions & 0 deletions src/exercises/19/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
// Comment below what did you understand from the previous 3 exercises about
// - prototype
// - __proto__

/**
* for every class Prototype is a default entry we have
* its like a blueprint of the object
* and __proto__ gives the prototype of the prototype of object
* we can add methods to prototype as follows
* - Book.prototype.getDetails = function() { ... }
* when we console.log any object of Book class it has prototype(even if the object is empty i.e {})
* and we have this new getDetails function in Book.prototype
* These have Object methods like constructor, hasOwnProperty etc... along with getter and setter.
*/
11 changes: 9 additions & 2 deletions src/exercises/2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@
// - Fix the issue.

function divideTenByNumber(number) {
// Error: result is inside the local space of if and else blocks. So, scope of result is limited to only those blocks.
// Fix: move result above condition statement

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}`);
}


divideTenByNumber(0);
15 changes: 15 additions & 0 deletions src/exercises/20/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
// What is debugger;
// - Comment your understanding of it.
// - Paste the link of the MDN article here.


/**
* Debugger is a keyword in js
* - debugger
* it invokes all the debugging functionalities if present.
* we can use it like a breakpoint to stop the execution at the given point.
* and if any debugger methods are available it runs those functions and then it continues execution
* if no debugger functions are available then it has no effect.
* this helps to find particularly in which statement does the bug is appearing.
*
* MDN link: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger
* W3Schools: https://www.w3schools.com/js/js_debugging.asp
*
*/
31 changes: 31 additions & 0 deletions src/exercises/21/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,32 @@
// What are the different levels of logs and how do we print them to the console?

/**
* Different levels of logs are,
* TRACE: trace gives full visibility of what is happening inside the application
* - console.trace('hey')
* DEBUG: handles logging of information that needed to be diagnosed.
* - console.debug('hey')
* INFO: it is just informative. it can be used to give information about the steps that passed smoothly may be in an algorithm.
* - console.info('hey')
* WARN: used to warn about unexpected scenarios that may occurs without actually intrupting the controlflow of the program
* - console.warn('hey')
* ERROR: used to give error messages that oocured
* - console.error('hey')
* FATAL: it gives the critical information like operation fail which is required to move forward ( unable to connect server )
* - console.fatal('hey')
*
* the one that is widely used is console.log() -> used to print info about anything that occurs in our program. can be used for all levels of logs.
*/



console.trace("Hey!");
console.debug("Hey!");
console.info("Hey!");
console.warn("Hey!");
console.error("Hey!");
console.fatal("Hey!");


console.log("Hey!")

Binary file added src/exercises/22/Screenshot_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/Screenshot_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/Screenshot_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/Screenshot_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/Screenshot_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/Screenshot_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 14 additions & 0 deletions src/exercises/22/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,23 @@
function randomCalculator() {
let x = 10,
y = 0;
debugger;
x = x * 10 + 1 - (2 / 2) * 3;
y = x - 1 + 3 * 10 - 2;
x = x * 2 - (1 / 3) * 3;
x = x + 10 - 2 - 3 * 2;
console.log(x);
}

/**
* Initially add x and y variables to Watch section in Chrome debugging console.
* and in code add a debugger statement below first line so that we can track x and y values from intial position
* if added at the top they will not be created and it shows '< not available >'
* now reload the page it will automatically stop the execution at debugger statement in line8.
* and then click on `ctrl + '` to go step by step and track x and y values after each statement.
* also observe that after executing console.log we get the last x value logged in console.
*/



randomCalculator()
12 changes: 12 additions & 0 deletions src/exercises/22/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!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>Document</title>
</head>
<body>
<script src="./exercise.js"></script>
</body>
</html>
Loading