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
5 changes: 4 additions & 1 deletion src/exercises/1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
// - Fix the issue.

function printOneToTen() {
for (const number = 1; number <= 10; number++) {
for (let number = 1; number <= 10; number++) {
console.log(`\n${number}`);
}
}
// In the for loop before it was mentioned 'const number', const cannot be changed so we have to replace with 'let'

printOneToTen() //We should call the function
32 changes: 31 additions & 1 deletion src/exercises/10/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,34 @@
}
]
*/
function findVoteEligibleCandidates(populationList) {}
function findVoteEligibleCandidates(populationList) {

let voteEligible = populationList.filter((candidate)=> candidate.age >=18).map((candidate)=> candidate.name);
// here the filter function creates an array with the condition mentioned in it as age>=18
// and map will filter the array with only the names
voteEligible.forEach(name => console.log(name));
// forEach method is used to iterate over the array without a loop
}


const populationList = [
{
name:"Ravi",
age:28
},
{
name:"Teja",
age:28
},
{
name:"Dileep",
age:21
},
{
name:"Chandra",
age:17
}

]

findVoteEligibleCandidates(populationList)
15 changes: 14 additions & 1 deletion src/exercises/11/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,17 @@
// - Use Array methods
// - Do not use loops

function sumOfArray(inputArray) {}
function sumOfArray(inputArray) {

let sum = inputArray.reduce((a,b)=>a+b);
//here we are reducing the elements one-by-one after calling the function called (a,b) as a+b
//first a is assigned to '0' and the b is assigned as the first element in the array then 'a' is
//as the first element of array is gonna reduce and the 'a' is updated as sum of a,b and again b is assigned to the next element of array
//at last the array will contain no element then the value of 'a' is assigned to sum
//its more like for loop as we declare a=0, b=arr[i] then a += a+b

console.log(sum);
}

sumOfArray([1,2,3,4,5])

10 changes: 9 additions & 1 deletion src/exercises/12/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,13 @@ function errorFunction() {
}

function errorCaller() {
errorFunction();
try{
errorFunction(); // here we are using try catch to check whether the errorFunction() throws an error or not
// if an error occurs in the try block, the execution of the code in it will be stopped and catch will be executed
}
catch(error){
console.log("Error Occured: ",error) // the errorFunction() throws an error so that the code in the catch will executed
}
}

errorCaller();
19 changes: 17 additions & 2 deletions src/exercises/13/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,21 @@ const employee = {
lastName: "Teja",
age: 29,
id: 1122,
getFullName: function () {},
checkVoteEligiblity: function () {},

getFullName: function () {
console.log("Full Name: "+this.firstName+" "+this.lastName) // in this function we using 'this' keyword to refer the employee object
// we can able to call the object in every function mentioned below
},

checkVoteEligiblity: function () {
if(this.age>=18){ // here we are checking whether the age of the employee object is greater than 18 or not
console.log("Eligible for vote")
}
else{
console.log("Not Eligible for vote")
}
},
};

employee.getFullName() // here we are accessing the getFullName function
employee.checkVoteEligiblity()
5 changes: 5 additions & 0 deletions src/exercises/14/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ const employee = {
id: 1122,
getFullName: function () {
//Copy the solution from the exercise before this.
console.log("Full Name: "+this.firstName+" "+this.lastName) // this is the code i've used in 13th question for getFullName function
},
};

const newEmployee = {
firstName: "New",
lastName: "Employee",
getFullName : employee.getFullName, //it is a reference of getFullName function which is mentioned in the employee object
//when we call the getFullName function in newEmployee object, it will acquire the properties of function defined in employee object
};

newEmployee.getFullName()
16 changes: 12 additions & 4 deletions src/exercises/15/exercise.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
// Convert the below functions into arrow functions.

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

const isEven = function (num) {
const greetings = () => "Hello World";

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

const isEven = num => num%2==0; //this arrow function returns true if num is divisible by 2 or it returns false

console.log(greetings())
console.log(isEven(6))
console.log(isEven(9))
21 changes: 20 additions & 1 deletion src/exercises/16/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,24 @@
// - Create function for all the possible functionalities.

class Leave {
//...
constructor(employeeName, startDate, endDate){
this.employeeName = employeeName;
this.startDate = startDate;
this.endDate = endDate;
}

requestLeave(){
console.log(`Leave requested by ${this.employeeName} from the date ${this.startDate} to ${this.endDate}`);
}
approveLeave(){
console.log(`Leave approved for ${this.employeeName}`);
}
rejectLeave(){
console.log(`Leave rejected for ${this.employeeName}`);
}
}

const newPerson = new Leave("Dileep Chandra","29th June 2023","31st June 2023");
newPerson.requestLeave();
newPerson.approveLeave();
newPerson.rejectLeave();
66 changes: 66 additions & 0 deletions src/exercises/17/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,67 @@
// Extend the Leave class, to create different classes for different Leave types.
class Leave {
constructor(employeeName, startDate, endDate){
this.employeeName = employeeName;
this.startDate = startDate;
this.endDate = endDate;
}

requestLeave(){
console.log(`Leave requested by ${this.employeeName} from the date ${this.startDate} to ${this.endDate}`);
}
approveLeave(){
console.log(`Leave approved for ${this.employeeName}`);
}
rejectLeave(){
console.log(`Leave rejected for ${this.employeeName}`);
}
}

// there will be some types of leaves: sick leave, vacation leave, maternity leave
class sickLeave extends Leave{
constructor(employeeName, startDate, endDate, sick){
super(employeeName, startDate, endDate);
this.sick = sick;
}

leaveforSick(){
console.log(`Leave requested by ${this.employeeName} for being Sick from the date ${this.startDate} to ${this.endDate}, suffering from ${this.sick}`);
}
}

class vacLeave extends Leave{
constructor(employeeName,startDate,endDate,place){
super(employeeName, startDate, endDate);
this.place = place;
}
leaveforVac(){
console.log(`Leave requested by ${this.employeeName} to go ${this.place} for vacation from the date ${this.startDate} to ${this.endDate}`);

}
}

class maternityLeave extends Leave{
constructor(employeeName,startDate,endDate){
super(employeeName, startDate, endDate);
}

leaveforMaternity(){
console.log(`Maternity Leave requested by ${this.employeeName} from the date ${this.startDate} to ${this.endDate}`);

}
}

const newPerson = new Leave("Dileep","29th June 2023","31st June 2023");
const person1 = new sickLeave("Surya","29th july 2023","31st july 2023", "Fever");
const person2 = new vacLeave("Venky","29th May 2023","31st may 2023", "Ooty");
const person3 = new maternityLeave("Anu","29th Aug 2023","31st Aug 2023");

newPerson.requestLeave();
newPerson.approveLeave();
newPerson.rejectLeave();

person1.leaveforSick();
person2.leaveforVac();
person2.rejectLeave();
person3.leaveforMaternity();
person3.approveLeave();
20 changes: 20 additions & 0 deletions src/exercises/18/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
// 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 {sickLeave} from '..17/exercise.js';
import {maternityLeave} from '../17/exercise.js';
import {vacLeave} from '../17/exercise.js';


const person1 = new sickLeave("Surya","29th july 2023","31st july 2023", "Fever");
const person2 = new vacLeave("Venky","29th May 2023","31st may 2023", "Ooty");
const person3 = new maternityLeave("Anu","29th Aug 2023","31st Aug 2023");

person1.leaveforSick();
person2.leaveforVac();
person2.rejectLeave();
person3.leaveforMaternity();
person3.approveLeave();

// by using import we can extract all the function and modules from the exported modules
// export is used to export all the modules and functions to the other files, we can able to access all the contents by importing the exported function
// we are making available to all the files which imports the exported class/modules/functions
19 changes: 19 additions & 0 deletions src/exercises/19/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
// Comment below what did you understand from the previous 3 exercises about
// - prototype
// - __proto__


//In the last 3 exercises, i came to know the Leave class creation which contains some attributes like EmployeeName, startDate and endDate
//in a prototype object it contains all of the methods and functions mentioned in a class

//By extending the Leave class into vacationLeave, sickLeave and maternityLeave allows us to inherit the properties and we can add other
//specific properties to the base class to behave according to the name of the class(reasons)

//In javaScript we can split the classes we created using extend keyword and we can access all the class, methods and functions by using import and
//export keywords.

//prototype is an object in JavaScript that is linked with every function and is used for inheritance and shared properties
//or methods among instances created from that function, by adding properties or methods to the prototype of a function,
//they become accessible to all instances of that function.


//__proto__ is a property available on all JavaScript objects, including functions and instances.
//It refers to the prototype object of the current object. It is used to access the prototype of an object,
//which is the object from which it inherits properties and methods.
10 changes: 8 additions & 2 deletions src/exercises/2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,17 @@
// - Fix the issue.

function divideTenByNumber(number) {
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}`);
}

// the issue is we declared the result variable in the if-else statements because,
//we can't access the variable outside the conditional statements which are declared inside the conditional statements

divideTenByNumber(30) //we should call the function here with some input in it
6 changes: 6 additions & 0 deletions src/exercises/20/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
// What is debugger;
// - Comment your understanding of it.
// - Paste the link of the MDN article here.


// Debugger is a tool in javaScript it can be written in between the code as 'debugger', it acts as a breakpoint in the execution
// once the execution is paused, we can see the process of execution line by line by using developer tools or debugging tools

// MDN link for debugger: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger
11 changes: 11 additions & 0 deletions src/exercises/21/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
// What are the different levels of logs and how do we print them to the console?
console.log("This is a log message");
// used to print the general messsage in the terminal

console.info("This is an info message");
// it is used to show the information to the user who is using the app/webpage

console.warn("This is a warning message");
// it shows the warning message like when there is a bad behavioural in the process or which leads to an error

console.error("This is an error message");
// it shows an error message in the console like a critical error showed in the red coloured text
Binary file added src/exercises/22/Screenshot 2023-06-15 131110.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 2023-06-15 131147.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 2023-06-15 131157.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 2023-06-15 131212.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 2023-06-15 131222.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 2023-06-15 131231.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 9 additions & 6 deletions src/exercises/22/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
// - What is "Watch" in chrome debugging console. Share a screenshot of the watch variables at each step.

function randomCalculator() {
let x = 10,
y = 0;
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;
debugger; //when the debugger attached to this code we can access through every breakpoint from start to end of the code execution
// i've attached some screenshot pngs when im running the code going through every breakpoint
let x = 10, y = 0;
x = x * 10 + 1 - (2 / 2) * 3; //98
y = x - 1 + 3 * 10 - 2; //125
x = x * 2 - (1 / 3) * 3; //195
x = x + 10 - 2 - 3 * 2; //197
console.log(x);
}

randomCalculator()
14 changes: 12 additions & 2 deletions src/exercises/23/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,24 @@ class Printer {
}

noDelayPrint() {
console.log(`You asked me to print the sheet ${this.index}`);
console.log(`You asked me to print the 1sheet ${this.index}`);
setTimeout(this.print, 0); // 0 milli-sec delay
this.index++;
}

noDelayPrint() {
console.log(`You asked me to print the sheet ${this.index}`);
console.log(`You asked me to print the 2sheet ${this.index}`);
setTimeout(this.print, 1000); //1 sec dely
this.index++;
}

}

let k = new Printer();
k.print()
k.noDelayPrint()

//here two noDelayPrint functions have been written, the second one is overwritten on the first one
//after calling the noDelayPrint, it will print "You asked me to print the 2sheet 0" as the value of the index=0
//after printing the whole thing which is in the console log it will wait for 1 second then it will call print function which is declared in
//starting of the class itself and returns undefined value as the index is declared in the constructor
Loading