Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added day1 demo files #29

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
16 changes: 16 additions & 0 deletions Day1/day1.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>

<head>
<meta content="text/html;charset=utf-8" http-equiv="Content-Type">
<meta content="utf-8" http-equiv="encoding">
</head>

<title>Pradeep Singh</title>

<body>
<h1 style="text-align: center;">Test Program</h1>
<b>Loading JS File</b>
<script src="day1.js"></script>
</body>

</html>
71 changes: 71 additions & 0 deletions Day1/day1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

alert('Hello World');
console.log('Hello World');
console.error('This is an error');
console.warn('This is a warning');


// let age = 30;

// age = 31;

const name = 'Pradeep';
const age = 24;
const rating = 3.5;
const isCool = true;
const x = null;
const y = undefined;
let z;

console.log(typeof z);


console.log('My name is ' + name + ' and I am ' + age);

console.log(`My name is ${name} and I am ${age}`);

const s = 'Hello World';
let val;
val = s.length;


// Change case
val = s.toUpperCase();
val = s.toLowerCase();
val = s.substring(0, 5);

// Split into array
val = s.split('');



// ARRAYS - Store multiple values in a variable
const numbers = [1,2,3,4,5];
const fruits = ['apples', 'oranges', 'pears', 'grapes'];
console.log(numbers, fruits);

// Get one value - Arrays start at 0
console.log(fruits[1]);

// Add value
fruits[4] = 'blueberries';

// Add value using push()
fruits.push('strawberries');

// Add to beginning
fruits.unshift('mangos');

// Remove last value
fruits.pop();

// // Check if array
console.log(Array.isArray(fruits));

// // Get index
console.log(fruits.indexOf('oranges'));





14 changes: 14 additions & 0 deletions Day2/day2.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>

<body>
<script src="day2.js"></script>
</body>

</html>
124 changes: 124 additions & 0 deletions Day2/day2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
let marks = [50, 80, 100, 90, 65, 10]
/*
different mark slabs :
>=90 : grade A+
>=80 and <90 : grade A
>=70 and <80 : grade B+
>=60 and <70 : grade B
>=50 and <60 : grade C+
>=40 and <50 : grade C
<40 : fail
*/

// forEach syntax and switch case.
marks.forEach((mark) => {
let status;
if (mark >= 90) {
status = "A+"
} else if (mark >= 80 && mark < 90) {
status = "A"
} else if (mark >= 70 && mark < 80) {
status = "B+"
} else if (mark >= 60 && mark < 70) {
status = "B"
} else if (mark >= 50 && mark < 60) {
status = "C+"
} else if (mark >= 40 && mark < 50) {
status = "C"
} else {
status = "fail"
}
console.log(`Result when marks obtained = ${mark} : ${status}`)
})

// functions :
//declaring a function without a parameter
function functionName() {
console.log("creating a function without a parameter!")
}
functionName() // calling function by its name and with parentheses

// function without parameter, a function which make a number square
function square() {
let num = 2
let sq = num * num
console.log(sq)
}
square()

// function without parameter
function addTwoNumbers() {
let numOne = 10
let numTwo = 20
let sum = numOne + numTwo

console.log(sum)
}
addTwoNumbers() // a function has to be called by its name to be executed

// function without parameter but returning something.
function printFullName() {
let firstName = 'Asabeneh'
let lastName = 'Yetayeh'
let space = ' '
let fullName = firstName + space + lastName
return fullName
}
console.log(printFullName())

// parameterised function.
function areaOfCircle(r) {
let area = Math.PI * r * r
return area
}
console.log(areaOfCircle(10)) // should be called with one argument


// with many parameters : this function takes array as a parameter and sum up the numbers in the array
function sumArrayValues(arr) {
let sum = 0;
for (let i = 0; i < arr.length; i++) {
sum = sum + arr[i];
}
return sum;
}
const numbers = [1, 2, 3, 4, 5];
console.log(sumArrayValues(numbers));

// with unlimited and variable number of arguments.
function sumAllNums() {
let sum = 0
for (let i = 0; i < arguments.length; i++) {
sum += arguments[i]
}
return sum
}

console.log(sumAllNums(1, 2, 3, 4)) // 10
console.log(sumAllNums(10, 20, 13, 40, 10)) // 93
console.log(sumAllNums(15, 20, 30, 25, 10, 33, 40)) // 173

// with unlimited number of arguments in an arrow function.
const sumAllNumsArrow = (...args) => {
let sum = 0
for (const element of args) {
sum += element
}
return sum
}

console.log(sumAllNumsArrow(1, 2, 3, 4)) // 10
console.log(sumAllNumsArrow(10, 20, 13, 40, 10)) // 93
console.log(sumAllNumsArrow(15, 20, 30, 25, 10, 33, 40)) // 173


// Arrow functions
const findSquare = n => {
return n * n
}

console.log(findSquare(2)) // -> 4

// one line. implicit return.
const findSquareOneLine = n => n * n // -> 4
console.log(findSquareOneLine(2))