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
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"liveServer.settings.port": 5501
}
6 changes: 5 additions & 1 deletion src/exercises/1/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
// - comment the reason for failure.
// - Fix the issue.

/* failure due to using of const keyword
const keyword declare variable as a block constant
reassigning of varible is not possible
*/
function printOneToTen() {
for (const number = 1; number <= 10; number++) {
for (let number = 1; number <= 10; number++) {
console.log(`\n${number}`);
}
}
9 changes: 8 additions & 1 deletion src/exercises/10/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,11 @@
}
]
*/
function findVoteEligibleCandidates(populationList) {}
function findVoteEligibleCandidates(populationList) {
let elibileCandidates = populationList.filter(function (candidates) {
if (candidates.age > 18) {
return true;
}
});
console.log(elibileCandidates);
}
7 changes: 6 additions & 1 deletion src/exercises/11/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@
// - Use Array methods
// - Do not use loops

function sumOfArray(inputArray) {}
function sumOfArray(inputArray) {
let result = inputArray.reduce(function (total, age) {
return total + age;
}, 0);
console.log(result);
}
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 block is to run the code to overcome the error exceptions
//The catch statement allows you to define a block of code to be executed, if an error occurs in the try block.
//both try block and catch block declare as a pair
try {
errorFunction();
} catch (err) {
console.log(err);
}
}
11 changes: 9 additions & 2 deletions src/exercises/13/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ 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";
}
return "NotEligible";
},
};
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.
return this.firstName + " " + this.lastName;
},
};

const newEmployee = {
firstName: "New",
lastName: "Employee",
};
//call function used to invoke (call) a method with an owner object as an argument.
//by using call(), an object can use a method belonging to another object.

employee.getFullName.call(newEmployee);
8 changes: 6 additions & 2 deletions src/exercises/15/exercise.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
// Convert the below functions into arrow functions.

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

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

class Leave {
export default class Leave {
//...
constructor(firstName, lastName, id, gender) {
this.firstName = firstName;
this.lastName = lastName;
this.id = id;
this.gender = gender;
}
display() {
return (
this.firstName +
" " +
this.lastName
);
}
}

20 changes: 20 additions & 0 deletions src/exercises/17/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,21 @@
// Extend the Leave class, to create different classes for different Leave types.

import Leave from "../16/exercise.js";
export class SickLeave extends Leave {
constructor(firstName, lastName, id, gender) {
super(firstName, lastName, id, gender);
this.reason = "Sick";
}
show() {
console.log(this.display() + " applying " + this.reason + " Leave");
}
}
export class CasualLeave extends Leave {
constructor(firstName, lastName, id, gender) {
super(firstName, lastName, id, gender);
this.reason = "Casual";
}
show() {
console.log(this.display() + " applying " + this.reason + " Leave");
}
}
28 changes: 28 additions & 0 deletions src/exercises/18/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,31 @@
// 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, CasualLeave } from "../17/exercise";
const ob1 = new SickLeave("Sai", "Ram", 21, "m");
ob1.show();

/*
about import :
The import keyword allows you to import a JavaScript module. Importing a module allows you
to pull any items from that module into the current code file. When we import a module, we
start the expression with the import keyword. Then, we identify what parts of the module we are
going to import. Then, we follow that with the "from" keyword, and finally we finish with the path
to the module file. The from keyword and file path tell the interpreter where to find the module we are importing.
Syntax:
import { export_function,varibles } from "file_path"
//when we using name exports
import export_function,varible from "./file_path";
//when we using defaule exports

about export:
The export keyword make the selected items in the module avaliable to other other module.
there different types of export types:
//name export
export { ItemName1,ItemName2.. };
export let name1, name2..;
//deafult export
export default name1;
export default class Class_name;
*/
10 changes: 10 additions & 0 deletions src/exercises/19/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
// Comment below what did you understand from the previous 3 exercises about
// - prototype
// - __proto__

/*
Prototypes are the mechanism by which JavaScript objects inherit features from one another.
Prototypes are a powerful and very flexible feature of JavaScript, making it possible to reuse
code and combine objects.
Every object in JavaScript has a built-in property, which is called its prototype. The prototype
is itself an object, so the prototype will have its own prototype, making what's called a prototype chain.
The chain ends when we reach a prototype that has null for its own prototype.
__proto__ is one of the function of prototype
*/
6 changes: 3 additions & 3 deletions src/exercises/2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
// - comment the reason for failure.
// - Fix the issue.

//let is a block variable, there can not accessed from out of the block { }
function divideTenByNumber(number) {
if (number != 0) {
let result = 10 / number;
var result = 10 / number;
} else {
let result = "Indeterminate";
var result = "Indeterminate";
}

console.log(`Result after dividing 10 by ${number} is ${result}`);
}
13 changes: 13 additions & 0 deletions src/exercises/20/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// What is debugger;
// - Comment your understanding of it.
// - Paste the link of the MDN article here.

/*
debugging means the process of finding the bugs or error in the code. debugger will help to understand
the code line by line,by using this identification of dugs in code is possible.
we can start debugging the code by placing the keyword - debugger
The debugger statement invokes any available debugging functionality, such as setting a breakpoint.
If no debugging functionality is available, this statement has no effect

By using this debugger concept we can understand the line by line execution of the code, and find the place of
error occuring.

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

/*JavaScript has support for logging messages at various levels. They are as follows, with their associated method and a description of their output in the console:

Plaintext—console.log() outputs unstyled text.
Info—console.info() typically outputs text with a blue background.
Warn—console.warn() typically outputs text with a yellow background.
Error—console.error() typically outputs text with a red background.
*/

console.log("Hello World");
console.dir("Hello World"); //outputs unstyled text.

console.error("error"); //typically outputs text with a red background.

console.warn("warning"); //typically outputs text with a yellow background.

console.info("information"); //display the information
3 changes: 2 additions & 1 deletion src/exercises/22/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
// - What is "Watch" in chrome debugging console. Share a screenshot of the watch variables at each step.

function randomCalculator() {
debugger;
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;
console.log(x);
console.log(x); //197
}
Binary file added src/exercises/22/screenshots/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/screenshots/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/screenshots/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/screenshots/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/screenshots/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/screenshots/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.
11 changes: 11 additions & 0 deletions src/exercises/23/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ class Printer {
this.index++;
}
}

/*
Here there are two noDelayPrint() and the last function will overcome the above functions and
start execution.

yes, 'this' inside print function referrring to an instance of Printer.
In JavaScript, the this keyword refers to an object.

In this class there are two methods with same name, i have observed that the last method is
overridding the above method, and start execution.
*/
3 changes: 3 additions & 0 deletions src/exercises/24/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
// - Share the resource link here.
// - Update all the exercises you have finished above by following the style guide.
// From the next exercise write your code following the style guide


//Resource Link:(https://www.w3schools.com/js/js_conventions.asp)
18 changes: 18 additions & 0 deletions src/exercises/25/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,19 @@
// Read what is a closure and give an example here


/*A closure is the combination of a function bundled together (enclosed) with references to its
surrounding state.In other words, a closure gives you access to an outer
function's scope from an inner function. In JavaScript, closures are created every time a function
is created, at function creation time.
inner function can access the outer function scope and variables by closure in javaScript
*/

function init() {
var name = "Mozilla"; // name is a local variable created by init
function displayName() {
// displayName() is the inner function, a closure
console.log(name); // use variable declared in the parent function
}
displayName();
}
init();
52 changes: 52 additions & 0 deletions src/exercises/26/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,56 @@

const counter = (function () {
//Your code goes here.
let privateCounter = 0;
function changeBy(val) {
privateCounter += val;
}

return {
increment() {
changeBy(1);
},

decrement() {
changeBy(-1);
},

value() {
return privateCounter;
},
};
})();

console.log(counter.value()); // 0

console.log(counter.increment());
console.log(counter.increment());

console.log(counter.value()); //2

console.log(counter.decrement());

console.log(counter.value()); //1


//yes, in this exercise we use anonymus function
//At line number 8
/* (function(){
/..
})();
*/

//IIFE(immediately invoking function expression)
/*Syntax:
(function(){
//statements..
})();

(()=>
//statements..
)();

In Javascript the function are invoked immediately with out call them with the help of IIFE
*/


13 changes: 10 additions & 3 deletions src/exercises/27/exercise.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,24 @@
// What is a callback?

function welcome(name) {
/*A callback function is a function passed into another function as an argument.
This technique allows a function to call another function
A callback function can run after another function has finished
A callback ia a function that is to be executed after another function has
finished executing--hence the name "callback"
*/

function welcome(name, myCallBack) {
setTimeout(() => {
console.log(`Welcome ${name}`);
myCallBack()
}, 1000);
}

function success() {
console.log("Greetings successful!!");
}

welcome();
success();
welcome("Apxor", success);

// In the above example:
// - Before welcoming, success message is printed.
Expand Down
Loading