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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
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.multiRootWorkspaceName": "JSExercises"
}
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}`);
}
}
// const cannot be changed once declared So added let instead of that
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 inputArray =
// [
// {
// name:"Ravi",
// age:28
// },
// {
// name:"Teja",
// age:28
// }
// ]

function findVoteEligibleCandidates(populationList) {
populationList.forEach( item => {
if (item.age >= 18)
console.log(item.name)
})
}

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

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

// sumOfArray([1,4,5])
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(err) {
console.log(err)
}
}

// errorCaller()
17 changes: 15 additions & 2 deletions src/exercises/13/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ 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) {
console.log("You are eligible to vote")
return true
}
else {
console.log("You are not eligible to vote")
return false
}
},
};

// console.log(employee.checkVoteEligiblity())
8 changes: 7 additions & 1 deletion src/exercises/14/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,16 @@ const employee = {
id: 1122,
getFullName: function () {
//Copy the solution from the exercise before this.
if(arguments.length !== 0)
return arguments[0] + " " + arguments[1]
else
return this.firstName + " " + this.lastName
},
};

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

console.log(employee.getFullName(newEmployee.firstName, newEmployee.lastName))
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 () {
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(4));
// console.log(isEven(3));
11 changes: 10 additions & 1 deletion src/exercises/16/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
// - Identify the class variables
// - Create function for all the possible functionalities.

class Leave {
export class Leave {
//...
constructor(days) {
this.days = days
}
getDaysCount() {
return this.days
}
}

// let leave = new Leave(10);
// console.log(leave.getDaysCount())
14 changes: 14 additions & 0 deletions src/exercises/17/exercise.js
Original file line number Diff line number Diff line change
@@ -1 +1,15 @@
// Extend the Leave class, to create different classes for different Leave types.

import {Leave} from '../16/exercise.js';

export class SickLeave extends Leave {
constructor(days) {
super(days)
}
getLeaveDetails() {
return `this is a Sick leave for ${this.getDaysCount()} days`
}
}

// const sickLeave = new SickLeave(10)
// console.log(sickLeave.getLeaveDetails())
14 changes: 14 additions & 0 deletions src/exercises/17/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@


<!doctype HTML>
<html>

<head>
</head>

<body>
<div>Exercise 17</div>
<script type="module" src="./exercise.js"></script>
<script type="module" src="../16/exercise.js"></script>
</body>
</html>
21 changes: 21 additions & 0 deletions src/exercises/18/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,24 @@
// 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";

// here the import i used variable import
//Modules with functions or variables can be stored in any external file.

// There are two types of exports: Named Exports and Default Exports.

// Named Exports
// Let us create a file named person.js, and fill it with the things we want to export.

// You can create named exports two ways. In-line individually, or all at once at the bottom.

// Default Exports
// Let us create another file, named message.js, and use it for demonstrating default export.

// You can only have one default export in a file.
const sickLeave = new SickLeave(10)
console.log(sickLeave.getLeaveDetails())

16 changes: 16 additions & 0 deletions src/exercises/18/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@


<!doctype HTML>
<html>

<head>
</head>

<body>
<div>Yeah</div>
<script type="module" src="../16/exercise.js"></script>
<script type="module" src="../17/exercise.js"></script>
<script type="module" src="./exercise.js"></script>

</body>
</html>
41 changes: 41 additions & 0 deletions src/exercises/19/exercise.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,44 @@
// Comment below what did you understand from the previous 3 exercises about
// - prototype
// - __proto__

// Prototype:
// The prototype object is special type of enumerable object to which additional properties can be attached to it which will be shared across all the instances of it's constructor function.

// So, use prototype property of a function in the above example in order to have age properties across all the objects as shown below.

// function Student() {
// this.name = 'John';
// this.gender = 'M';
// }

// Student.prototype.age = 15;



// __proto

// Every object which is created using literal syntax or constructor syntax with the new keyword, includes __proto__ property that points to prototype object of a function that created this object.

// function Student() {
// this.name = 'John';
// this.gender = 'M';
// }

// var studObj = new Student();

// console.log(Student.prototype); // object
// console.log(studObj.prototype); // undefined
// console.log(studObj.__proto__); // object

// console.log(typeof Student.prototype); // object
// console.log(typeof studObj.__proto__); // object

// console.log(Student.prototype === studObj.__proto__ ); // true


// prototype comes into picture.
// First of all, JavaScript engine checks whether toString() method is attached to studObj? (It is possible to attach a new function to a instance in JavaScript).
// If it does not find there then it uses studObj's __proto__ link which points to the prototype object of Student function.
// If it still cannot find it there then it goes up in the heirarchy and check prototype object of Object function because all the objects are derived from Object in JavaScript, and look for toString() method.
//Thus, it finds toString() method in the prototype object of Object function and so we can call studObj.toString().
7 changes: 5 additions & 2 deletions src/exercises/2/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
// - 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}`);
}
// result is declared in the if clause changing it to divideTenByNumber function clause
// 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.


// In the debugger window, you can set breakpoints in the JavaScript code.

// At each breakpoint, JavaScript will stop executing, and let you examine JavaScript values.

// After examining values, you can resume the execution of code (typically with a play button).

// The debugger keyword stops the execution of JavaScript, and calls (if available) the debugging function.

// This has the same function as setting a breakpoint in the debugger.

// If no debugging is available, the debugger statement has no effect.

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

// console.log()
// console.log("Hello World!"); // Hello World!
// We can pass many log messages as arguments to the console.log() method.

// console.log("Hello World!", "How are you?"); // Hello World! How are you?
// We can also use the console.log() method to examing contents of an object.

// const Earth = {
// name: "Earth",
// age: "A Trillion Years",
// };

// // log object Earth
// console.log(Earth); // {name: "Earth", age: "A Trillion Years"}


// console.debug()
// We can also log information using the console.debug() method.
//This is just like the console.log() method but instead, the information logged using this can be seen only if the console is in debugging level.


// console.dir()
// While you can also examine the contents of objects using the console.log() method, this is no different from the console.dir() method which can also be used to examine the contents of an object.
// But there is a slight difference to it.
// If you are trying to view the contents of an HTML element using the console.log() method, you would see the content int he console just like how it is represented in plain HTML, not useful if you are trying to view the attributes and all other cool kinds of stuff.


// console.error()
// If you want to log an error instead of some information you can use the console.error() method.
// error
// console.error("This is a big error 🚫");
// The error will be in red color and will also show the line number where the error has happened.


// console.warn()
// if you want to log a warning instead of a pure error, you can use the console.warn() method.
// warning
// console.warn("This is just a warning ⚠️");


// console.table()
// If you want to view your contents of objects in a table-like structure, you can use the console.table() method.
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.
3 changes: 3 additions & 0 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;
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);
}

randomCalculator()
13 changes: 13 additions & 0 deletions src/exercises/22/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@


<!doctype HTML>
<html>

<head>
</head>

<body>
<div>Hi !</div>
<script src="./exercise.js"></script>
</body>
</html>
Loading