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

function printOneToTen() {
for (const number = 1; number <= 10; number++) {
for (let number = 1; number <= 10; number++) {
console.log(`\n${number}`);
}
}
printOneToTen();
33 changes: 20 additions & 13 deletions src/exercises/10/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@
// - Do not use loops

// Example of inputArray
/*
[
{
name:"Ravi",
age:28
},
{
name:"Teja",
age:28
}
]
*/
function findVoteEligibleCandidates(populationList) {}

const voters = [
{
name: "Ravi",
age: 28,
},
{
name: "Teja",
age: 8,
},
];

function findVoteEligibleCandidates(populationList) {
// const eligibleVoters = populationList.filter(function (person) {
// return person.age > 18;
// });
const eligibleVoters = populationList.filter((person) => person.age > 18);
console.log(eligibleVoters);
}
findVoteEligibleCandidates(voters);
23 changes: 22 additions & 1 deletion src/exercises/11/exercise.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
// Complete the below function. Print the sum of the elements in the given array.
// - Use Array methods
// - Do not use loops
//we will use reduce method it has extra argument in the function which is called accumulator
function sumOfArray(inputArray) {
const sum = inputArray.reduce(function (acc, val, index, arr) {
return acc + val;
}, 0);
return sum;
}
//the second argument of the redduce method is the intial value of the accumulator
//it can be any number

function sumOfArray(inputArray) {}
let inputArray = [1, 2, 3, 4, 5, 56, 33];
console.log(sumOfArray(inputArray));
//reduce cannot be used only for sum it can be used for finding the maximum elements
//it can be used whenever result should be single value

//chaining of the methods together
const movements = [200, 450, -400, 3000, -650, -130, 70, 1300];

const totalDeposit = movements
.filter((mov) => mov > 0)
.map((mov) => mov * 1.1)
.reduce((acc, mov) => acc + mov, 0);
console.log(totalDeposit);
6 changes: 6 additions & 0 deletions src/exercises/12/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ function errorFunction() {
function errorCaller() {
errorFunction();
}

try {
errorCaller();
} catch (e) {
console.log(e);
}
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 () {
console.log(this.firstName + " " + this.lastName);
},
checkVoteEligiblity: function () {
this.age > 18
? console.log("Eligible to vote")
: console.log("Not eligible to vote");
},
};
employee.getFullName();
employee.checkVoteEligiblity();
4 changes: 4 additions & 0 deletions src/exercises/14/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const employee = {
age: 29,
id: 1122,
getFullName: function () {
console.log(this.firstName + " " + this.lastName);
//Copy the solution from the exercise before this.
},
};
Expand All @@ -15,3 +16,6 @@ const newEmployee = {
firstName: "New",
lastName: "Employee",
};
newEmployee.getFullName = employee.getFullName;
newEmployee.getFullName();
//we can copy the properties(methods and data) from one object another another object in js
25 changes: 19 additions & 6 deletions src/exercises/15/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,23 @@ const greetings = function () {
return "Hello World";
};

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

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

console.log(greet());

const isEven = (num) => {
let result = num % 2 == 0 ? true : false;
return result;
};
console.log(isEven(10));
14 changes: 13 additions & 1 deletion src/exercises/16/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
// - Identify the class variables
// - Create function for all the possible functionalities.

class Leave {
export class Leave {
constructor(name, numberofdays) {
this.name = name;
this.numberofdays = numberofdays;
}
generateLeaveMessage() {
console.log(
`${this.name} is on leave for ${this.numberofdays} days because ${this.reason}`
);
}
//...
}
// const Bhavana = new Leave("Bhavana", 2, "not feeling well");
// console.log(Bhavana);
// Bhavana.generateLeaveMessage();
47 changes: 46 additions & 1 deletion src/exercises/17/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,46 @@
// Extend the Leave class, to create different classes for different Leave types.
// Extend the Leave class, to create different classes for different Leave types.;
// import { Leave } from "../16/exercise.js";

import { Leave } from "../16/exercise.js";
class SickLeave extends Leave {
constructor(name, age, reason = "sick Leave") {
super(name, age);
this.reason = reason;
}
generatingReason() {
super.generateLeaveMessage();
}
}

const sl = new SickLeave("Bhavana", 1);
sl.generatingReason();
class Vacation extends Leave {
constructor(name, age, reason = "Vacation") {
super(name, age);
this.reason = reason;
}
generatingReason() {
super.generateLeaveMessage();
}
}
const v = new Vacation("Bhavana", 4);
v.generatingReason();

//static = a method or property that belongs to a class
//not any one object
// class Car {
// static numberOfCars = 0;
// static beginRace() {
// console.log("The Race has begun");
// }
// constructor(model) {
// this.model = model;
// Car.numberOfCars += 1;
// }
// }
// let car1 = new Car("Mustang");
// let car2 = new Car("Corvette");
// let car3 = new Car("Corvette");

// console.log(Car.numberOfCars);
// Car.beginRace();
9 changes: 9 additions & 0 deletions src/exercises/17/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!DOCTYPE html>
<html>
<head>
<script type="module" src="./exercise.js"></script>
</head>
<body>
<h1>Hello</h1>
</body>
</html>
13 changes: 13 additions & 0 deletions src/exercises/18/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
// Use Javascript modules to create seperate files for each of the Leave type classes.
// - Comment your understanding about import
// - Comment your understanding about export

/*
there are two types of export
named export and default export
we export usinfg export keyword
export default we can send the value directly
when imported no need to use {}
*/

/* import modules from diffrenet pages and can be used in our code
we can import properties methods and classes */

//same exrcise in 16 and 17
24 changes: 24 additions & 0 deletions src/exercises/19/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,27 @@
// Comment below what did you understand from the previous 3 exercises about
// - prototype
// - __proto__

/*
protoype of a class has access to all the properties and methods in it
It can be accessed by all the instances created
If there are 100 instances for a particular class
and same code written tthere will be duplication of code
and wastage of resources will be there
*/

/*
__proto__ is property defined for every instance
it has all the properties and methods in it
*/

class Car {
constructor(name, color) {
(this.name = name), (this.color = color);
}
}

const c1 = new Car("Brezza", "white");
console.log(Car.prototype);
console.log(c1.__proto__);
console.log(Car.prototype === c1.__proto__);
8 changes: 6 additions & 2 deletions src/exercises/2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@
// - 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}`);
}
divideTenByNumber(3);

//result is defined but it is not in the scope of the function it is the scope of the if else block
14 changes: 14 additions & 0 deletions src/exercises/20/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
// What is debugger;
// - Comment your understanding of it.
// - Paste the link of the MDN article here.

//when we write the debugger keyword in code the breakpoint
//will be set.
//If no debugging functionality then debugger will not have any effect

//https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/debugger
function helloWorld() {
let a = 10;
let b = 20;
let c = 30;
debugger;
console.log(a + b + c);
}
helloWorld();
58 changes: 58 additions & 0 deletions src/exercises/21/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
// What are the different levels of logs and how do we print them to the console?
let x = 1;
let y = 2;
let z = 3;
console.log({ x, y, z });
let user = {
name: "Jesse",
contact: {
email: "codestackr@gmail.com",
},
};
console.table(user);
// console.log(user);
// console.log({ user });
console.log("Console log");
console.info("Console info");
console.debug("console debug");
console.warn("console warn");
console.error("console error");

//optional logs
//the statement will be logged if the condiiton is false
let isWorking = false;
console.assert(isWorking, "App is not working");
for (let i = 0; i < 10; i++) {
console.count("Counter 1");
}
console.countReset("Counter 1");
//this is used to reset the counter
console.count("Counter 1");

console.time();
setTimeout(() => {
console.timeEnd();
}, 5000);
setTimeout(() => {
console.timeLog();
}, 2000);

console.groupCollapsed();
console.log("I am in a group");
console.log("I am also in a group");
console.groupEnd();
console.log(
"%c This is yellow text on a blue background.",
"color:yellow; background-color:blue"
);
//console.clear(); //clear the console

// function one() {
// two();
// }
// function two() {
// three();
// }
// function three() {
// console.trace();
// }
// one();
11 changes: 7 additions & 4 deletions src/exercises/22/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
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;
x = x * 10 + 1 - (2 / 2) * 3; //x=98
y = x - 1 + 3 * 10 - 2; //y=125
x = x * 2 - (1 / 3) * 3; //x=195
x = x + 10 - 2 - 3 * 2; //x=197
console.log(x);
}
randomCalculator();
//watch windfdow is used to validate the particular value of the variable
//it is generrally used for checking purpose
8 changes: 8 additions & 0 deletions src/exercises/22/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<html>
<head>
<script src="exercise.js"></script>
</head>
<body>
<h1>Hello World</h1>
</body>
</html>
Loading