pull/408/merge
Satya_Surendra 6 months ago committed by GitHub
commit 2bd9553ab7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,4 @@
console.log(typeof('satya') );
console.log(typeof(20) );
console.log(typeof(null) );
console.log(typeof(undefined) );

@ -0,0 +1,26 @@
// 1.question
//Comments can make code readable
// 2.question
//Welcome to 30DaysOfJavaScript
// 3.question
/*
Comments can make code readable,
easy to reuse and informative
*/
// 6.question
let a, b, c, d;
// 7.question
let name = 'satya',
age = 20,
married = false,
id = 1;
// 8.question 9.question
let firstName = 'satya',
lastName = 'surendra',
maritalStatus = false,
country = 'Indian',
myage = 20;
// 10.question
let myAge = 20,
yourAge = 21;
console.log(myAge,yourAge);

@ -0,0 +1,4 @@
let name = 'satya',
maritalStatus = false,
abc = undefined,
cbd = null;

@ -0,0 +1,55 @@
// 1.question
let challenge = '30 Days Of JavaScript';
// 2.question
console.log(challenge);
// 3.question
console.log(challenge.length);
// 4.question
challenge.toUpperCase();
// 5.question
challenge.toLowerCase();
// 6.question
let firstWord = challenge.substr(0, 2);
let firstWord1 = challenge.substring(0, 2);
console.log(firstWord);
console.log(firstWord1);
// 7.question
let restWord = challenge.slice(3);
console.log(restWord);
// 8.question
console.log(challenge.includes('Script'));
// 9.question 10.question
let arr = challenge.split(' ');
console.log(arr);
// 11.question
let itCompany = 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon'.split(',');
console.log(itCompany);
// 12.question
console.log(challenge.replace('JavaScript', 'Python'));
// 13.question
console.log(challenge.charAt(15));
// 14.question
console.log(challenge.charCodeAt('J'));
// 15.question
console.log(challenge.indexOf(challenge));
// 16.question
console.log(challenge.lastIndexOf(challenge));
// 17.question
console.log('You cannot end a sentence with because because because is a conjunction'.indexOf('because'));
// 18.question
console.log('You cannot end a sentence with because because because is a conjunction'.lastIndexOf('because'));
// 19.question
console.log('You cannot end a sentence with because because because is a conjunction'.search('because'));
// 20.question
console.log(challenge.trim(challenge));
// 21.question
console.log(challenge.startsWith('30'));
// 22.question
console.log(challenge.endsWith('JavaScript'));
// 23.question
console.log(challenge.match(/a/g));
// 24.question
console.log('30 Days Of '.concat('JavaScript'));
// 25.question
let rep = challenge.repeat(2)
console.log(rep);

@ -0,0 +1,57 @@
// 1.question
console.log(
`The quote 'There is no exercise better for the heart than reaching down and lifting people up.' by John Holmes teaches us to help one another.`
);
// 2.question
console.log(
"Love is not patronizing and charity isn't about pity, it is about love. Charity and love are the same -- with charity you give love, so don't just give money but reach out your hand instead."
);
// 3.question
(10 === '10') ? console.log(true) : +'10';
// 4.question
(parseFloat('9.8') === 10)?console.log(true): Math.ceil(+'9.8')
// 5.question
if ('python'.includes('on')&&'jargon'.includes('on')) {
console.log(true);
}
// 6.question
if ('I hope this course is not full of jargon'.includes('jargon')) {
console.log(true);
}
// 7.question
console.log(Math.floor(Math.random() * 101));
// 8.question
console.log(Math.floor(Math.random() * (101 - 50)) + 50);
// 9.question
console.log(Math.floor(Math.random() * 225));
// 10.question
// 11.question
for (let i = 0; i < 5; i++) {
for (let j = 0; j < 5; j++) {
if (j == 1) {
console.log(1);
}
else if (j == 0 || j == 2) {
console.log(i+1);
} else {
console.log(Math.pow(i+1,j-1));
}
}
console.log(' ');
}
console.log(
`1 1 1 1 1
2 1 2 4 8
3 1 3 9 27
4 1 4 16 64
5 1 5 25 125`
);
// 12.question
let sent = 'You cannot end a sentence with because because because is a conjunction';
let i = sent.indexOf('because');
let j = sent.lastIndexOf('because');
let len = 'because'.length;
console.log(sent.slice(i, j+len));

@ -0,0 +1,13 @@
// 1.question
let word = 'Love is the best thing in this world. Some found their love and some are still looking for their love.';
console.log(word.match(/love/gi).length);
// 2.question
let word1 = 'You cannot end a sentence with because because because is a conjunction';
console.log(word1.match(/because/gi).length);
// 3.question
const sentence = '%I $am@% a %tea@cher%, &and& I lo%#ve %te@a@ching%;. The@re $is no@th@ing; &as& mo@re rewarding as educa@ting &and& @emp%o@weri@ng peo@ple. ;I found tea@ching m%o@re interesting tha@n any ot#her %jo@bs. %Do@es thi%s mo@tiv#ate yo@u to be a tea@cher!? %Th#is 30#Days&OfJavaScript &is al@so $the $resu@lt of &love& of tea&ching';
console.log(sentence.replace(/[^a-zA-Z0-9]/g, ''));
// 4.question
let word2 = 'He earns 5000 euro from salary per month, 10000 euro annual bonus, 15000 euro online courses per month.';
let arr = +(word2.replace(/[^0-9]/g, ''));
console.log(arr);

@ -0,0 +1,50 @@
// 1.question
let personInfo = {
firstName: 'satya',
lastName: 'surendra',
country: 'India',
city: 'Drakshaxxxx',
age: 20,
isMarried: false,
year:2002
};
Object.keys(personInfo).forEach(key => {
console.log(typeof personInfo[key]);
})
// 2.question
console.log(('10' == 10));
// 3.question
console.log((parseInt('9.8') == 10));
// 4.1.question
console.log(Boolean(1));
console.log(Boolean(true));
console.log(Boolean("satya"));
// 4.2.question
console.log(Boolean(0));
console.log(Boolean(false));
console.log(Boolean(""));
// 5.question
true //4>3
true //4>=3
false //4<3
false //4<=3
true //4==4
true //4===4
false //4!=4
false //4!==4
false //4!='4
true //4=='4
false //4==='4
console.log(('python'.length === 'jargon'.length));
// 6.question this is also same as the 5.question so iam skipping it
// 7.question
let now = new Date();
let year = now.getFullYear(),
month = now.getMonth(),
date = now.getDate(),
day = now.getDay(),
hrs = now.getHours(),
min = now.getMinutes(),
time = now.getTime();

@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="./level2.js"></script>
</body>
</html>

@ -0,0 +1,77 @@
// 1.question
let base = parseInt(prompt('Enter base:', 0));
let height = parseInt(prompt('Enter height:', 0));
let area = 0.5 * base * height;
alert(area);
// 2.question
let a = parseInt(prompt('Enter side a:', 0));
let b = parseInt(prompt('Enter side b:', 0));
let c = parseInt(prompt('Enter side c:', 0));
let perimeter = a + b + c;
alert(perimeter);
// 3.question
let l = parseInt(prompt('Enter the length:', 0));
let w = parseInt(prompt('Enter the width:', 0));
let rectArea = l * w;
alert(rectArea);
let rectPerimeter = 2 * (l + w);
alert(rectPerimeter);
// 4.question
let radius = parseInt(prompt('Enter the radius:', 0));
let circleArea = 3.14 * r * radius;
alert(circleArea);
let circlePerimeter = 2 * 3.14 * radius;
alert(circlePerimeter);
// 5.question
alert('Slope of y=2x-2 is :' + 2);
// 6.question
function findSlope(x1, y1, x2, y2) {
let m = (y2 - y1) / (x2 - x1);
alert(m)
}
findSlope(2, 2, 6, 10);
// 7.question I don't understand the question so iam skipping it
// 8.question
// 9.question
let hrs = parseInt(prompt('Enter hours:', 0));
let rate = parseInt(prompt('Enter rate'), 0);
alert(`Your weekly earning is ${hrs * rate}`);
// 10.question
let name = 'satya';
if (name.lenth > 7) {
alert('Your name is long');
} else { alert('Your name is short'); }
// 11.question
let firstName = 'Asabeneh'
let lastName = 'Yetayeh'
if (firstName.length > lastName.length) {
alert(`Your first name, ${firstName} is longer than your family name, ${lastName}`);
}
// 12.question
let myAge = 250
let yourAge = 25
alert(`I am ${myAge - yourAge} years older than you`);
// 13.question
let drive = parseInt(prompt('Enter your birth year', 0));
let now = new Date().getFullYear();
if ((now - drive) > 18) {
alert(`You are ${now - drive} . You are old enough to drive`);
} else {
alert(`You are ${now - drive}. You will be allowed to drive after ${18 - now - drive} years`);
}
// 14.question
// 15.question
let present = new Date();
let year = present.getFullYear(),
month = present.getMonth(),
date = present.getDate(),
hours = present.getHours(),
min = present.getMinutes();
if ((month + 1) < 10) { (month + 1) = '0+(month+1)'; }
if ((date + 1) < 10) { (date + 1) = '0+(date+1)'; }
if ((hours + 1) < 10) { (hours + 1) = '0+(date+1)'; }
if ((min + 1) < 10) { (min + 1) = '0+(date+1)'; }
alert(`${year}-${month}-${date} ${hours}:${min}`);
alert(`${date}-${month}-${year} ${hours}:${min}`);
alert(`${date}/${month}/${year} ${hours}:${min}`);

@ -0,0 +1,12 @@
// 1.question
let now = new Date();
let hrs = now.getHours(),
min = now.getMinutes(),
year = now.getFullYear(),
mon = now.getMonth(),
date = now.getDate();
if (hrs < 10) { hrs = '0' + hrs; }
if (min < 10) { min = '0' + min; }
if (mon < 10) { mon = '0' + mon; }
if (date < 10) { date = '0' + date; }
console.log(`${year}-${mon}-${date} ${hrs}:${min}`);

@ -0,0 +1,15 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="./level3.js"></script>
</body>
</html>

@ -0,0 +1,20 @@
// 1.question
let age = parseInt(prompt('Enter your age:', 0));
(age > 18) ? alert('You are old enough to drive.') : alert(`You are left with ${18 - age} years to drive.`);
// 2.question
let yourAge = parseInt(prompt('Enter your age:', 0));
let myAge = age;
if (yourAge > myAge) {
console.log(`Your are ${yourAge-myAge} years older than me.`);
} else {
console.log(`Your are ${myAge - yourAge } years younger than me.`);
}
// 3.question
let a = parseInt(prompt('Enter number a:', 0));
let b = parseInt(prompt('Enter number b:', 0));
if (a > b) { console.log(`${a} is greater than ${b}`); }
else { console.log(`${b} is greater than ${a}`); }
(a>b)?console.log(`${a} is greater than ${b}`):console.log(`${b} is greater than ${a}`);
// 4.question
let num = parseInt(prompt('Enter number:', 0));
((num%2)==0)?console.log(`${num} is an even number`):console.log(`${num} is an odd number`);

@ -0,0 +1,34 @@
// 1.question
let marks = parseInt(prompt('Enter the marks:', 0));
if (marks>=90&&marks<=100) {
console.log('A');
}else if (marks>=70&&marks<90) {
console.log('B');
}else if (marks>=60&&marks<70) {
console.log('C');
}else if (marks>=50&&marks<60) {
console.log('D');
} else {
console.log('F');
}
// 2.question
let month = prompt('Enter the month name:');
if (month == 'September' || month == 'October' || month == 'November') {
console.log('The season is Autumn');
} else if (month == 'December' || month == 'January' || month == 'February') {
console.log('The season is Winter');
} else if (month == 'March' || month == 'April' || month == 'May') {
console.log('The season is Spring');
} else if (month == 'June' || month == 'July' || month == 'August') {
console.log('The season is Summer');
} else {
console.log('Invalid month');
}
// 3.question
let day = prompt('What is the day today?','Enter only days.').to;
if (day.toLowerCase() == 'saturday' || day.toLowerCase() == 'sunday') {
console.log(`${day} is a weekend.`);
} else {
console.log(`${day} is a working day.`);
}

@ -0,0 +1,78 @@
// 1.question
let months = [
{
month: 'january',
days:31
},
{
month: 'february',
days:28
},
{
month: 'march',
days:31
},
{
month: 'april',
days:30
},
{
month: 'may',
days:31
},
{
month: 'june',
days:30
},
{
month: 'july',
days:31
},
{
month: 'august',
days:31
},
{
month: 'september',
days:30
},
{
month: 'octuber',
days:31
},
{
month: 'november',
days:30
},
{
month: 'december',
days:31
},
]
let m = prompt('Enter a month:');
for (let i = 0; i < months.length; i++){
if (months[i].month == m.toLowerCase()) {
alert(`${m} has ${months[i].days} days.`);
}
}
// 2.question
let year = parseInt(prompt('Enter the year:', 0));
for (let i = 0; i < months.length; i++){
if ((year % 4) == 0) {
if (m.toLowerCase() == 'february') {
alert(`${m} has 29 days.`);
break;
}
else {
if (m.toLowerCase() == months[i].month) {
alert(`${m} has ${months[i].days} days.`);
}
}
}
else {
if (m.toLowerCase() == months[i].month) {
alert(`${m} has ${months[i].days} days.`);
}
}
}

@ -0,0 +1,14 @@
export default Countries = [
'Albania',
'Bolivia',
'Canada',
'Denmark',
'Ethiopia',
'Finland',
'Germany',
'Hungary',
'Ireland',
'Japan',
'Kenya'
]

@ -0,0 +1,73 @@
// 1.question
let emt = [];
// 2.question
let five = [1, 2, 3, 4, 5];
// 3.question
console.log(five.length);
// 4.question
let f = 0, l = five.length - 1, mid = (f + l) / 2;
console.log(five[f], five[l], five[mid]);
// 5.question
let mixedDataTypes = [
1,
'satya',
false,
20,
null
];
// 6.question
let itCompanies = [
'Facebook',
'Google',
'Microsoft',
'Apple',
'IBM',
'Oracle',
'Amazon'
];
// 7.question
console.log(itCompanies);
// 8.question
console.log(itCompanies.length);
// 9.question
l = itCompanies.length - 1;
console.log(itCompanies[f], itCompanies[l], itCompanies[mid]);
// 10.question
itCompanies.forEach((company) => console.log(company));
// 11.question
itCompanies.forEach((company) => console.log(company.toUpperCase()));
// 12.question
console.log(itCompanies.toString());
// 13.question
(itCompanies.includes('Facebook')) ? console.log(itCompanies[itCompanies.indexOf('Facebook')]) : console.log('Not found');;
// 14.question
// itCompanies.map((c) => {
// let count = 0;
// let i = c.split(',');
// i.map((e) => {
// console.log(e);
// if (e.split(',') == 'o') { count++; }
// })
// if (count > 1) {
// // console.log(c);
// }
// // console.log(c);
// });
// 15.question
itCompanies.sort();
// 16.question
itCompanies.reverse();
// 17.question
itCompanies.slice(0, 2);
// 18.question
itCompanies.slice(l - 4, l - 1);
// 19.question
itCompanies.slice(mid, mid + 1);
// 20.question
itCompanies.shift();
// 21.question
itCompanies.splice(mid, 1, 0);
// 22.question
itCompanies.pop();
// 23.question
itCompanies.slice(0);

@ -0,0 +1,3 @@
import web_techs from "./web_techs";
console.log(web_techs);

@ -0,0 +1,9 @@
export default [
'HTML',
'CSS',
'JavaScript',
'React',
'Redux',
'Node',
'MongoDB'
]

@ -0,0 +1,128 @@
// 1.question
for (let i = 0; i < 10; i++){
//code
}
let i = 0;
while (i < 10) {
//code
i++;
}
i = 0;
do {
//cpde
i++;
} while (i < 10)
// 2.question
for (let i = 10; i >= 0; i--){
//code
}
i = 10;
while (i >=0) {
//code
i--;
}
i = 10;
do {
//cpde
i--;
} while (i >= 0)
// 3.question
let n;
for (i = 0; i < n; i++){
//code
}
// 4.question
let str = '';
for (i = 1; i < 8; i++){
for (let j = 1; j <=i; j++){
str+='#'
}
str += '\n';
}
console.log(str);
// 5.question
for (i = 0; i < 11; i++){
console.log(`${i} x ${i} = ${i*i}`);
}
// 6.question
for (i = 0; i < 11; i++){
console.log(`${i} ${Math.pow(i,2)} ${Math.pow(i,3)}`);
}
// 7.question
i = 0;
while (i < 101) {
if (i % 2 == 0) {
console.log(i);
}
i++;
}
// 8.question
i = 0;
while (i < 101) {
if (i % 2 != 0) {
console.log(i);
}
i++;
}
// 9.question
i = 0;
while (i < 101) {
let count = 0;
for (j = i; j > 0; j--){
if (i % j == 0) {
count++;
}
}
if (count == 2) {
console.log(i);
}
i++;
}
// 10.question
i = 0;
let sum = 0;
while (i < 101) {
sum += i;
i++;
}
console.log(`The sum of all numbers from 0 to 100 is ${sum}`);
// 11.question
i = 0;
let evenSum = 0;
while (i < 101) {
if (i % 2 == 0) {
evenSum += i;
}
i++;
}
let oddSum = sum-evenSum
console.log(`The sum of all numbers from 0 to 100 is ${evenSum} . And the sum of all odds from 0 tp 100 is ${sum - evenSum}`);
// 12.question
let sums = [oddSum, evenSum];
console.log(sums);
// 13.question
let rand = [];
for (i = 0; i < 5; i++){
rand.push(Math.floor(Math.random() * 10));
}
console.log(rand);
// 14.question
let uniqueRand = [];
for (i = 0; i < 5; i++){
let temp = Math.floor(Math.random() * 10);
while (uniqueRand.includes(temp)) {
temp = Math.floor(Math.random() * 10);
}
if (!uniqueRand.includes(temp)) {
uniqueRand.push(temp)
}
}
console.log(uniqueRand);
// 15.question
let code = '0123456789abcdefghijklnopqrstuvwxyz';
let id = '';
for (i = 0; i < 6; i++){
temp = Math.floor(Math.random() * code.length);
id += code[temp];
}
console.log(id);

@ -0,0 +1,146 @@
// 1.question
let code = '0123456789abcdefghijklnopqrstuvwxyz';
let id = '';
let rand = Math.floor(Math.random() * code.length);
for (let i = 0; i < rand; i++){
let rand = Math.floor(Math.random() * code.length);
id+=code[rand]
}
console.log(id);
// 2.question
let hexcode = '0123456789abcdef';
let hex = '#';
for (i = 0; i < 6; i++){
let rand = Math.floor(Math.random() * hexcode.length);
hex += hexcode[rand];
}
console.log(hex);
// 3.question
function rgb() {
return Math.floor(Math.random() * 255);
}
console.log(`rgb(${rgb()},${rgb()},${rgb()})`);
// 4.question
const countries = [
'Albania',
'Bolivia',
'Canada',
'Denmark',
'Ethiopia',
'Finland',
'Germany',
'Hungary',
'Ireland',
'Japan',
'Kenya'
];
let newCountries = [];
for (const iterator of countries) {
newCountries.push(iterator.toUpperCase());
}
console.log(newCountries);
// 5.question
let countryLen = [];
for (const iterator of countries) {
countryLen.push(iterator.length);
}
console.log(countryLen);
// 6.question
let newArr = [];
for (const iterator of countries) {
let temp = []
temp.push(iterator);
temp.push(iterator.slice(0,3).toUpperCase());
temp.push(iterator.length);
newArr.push(temp);
}
console.log(newArr);
// 7.question
let conLand = [];
for (const iterator of countries) {
if (iterator.includes('land')) {
conLand.push(iterator)
}
}
console.log(conLand);
// 8.question
let conIa = [];
for (const iterator of countries) {
if (iterator.includes('ia')) {
conIa.push(iterator);
}
}
console.log(conIa);
// 9.question
let max = 0;
let maxi = 0;
for (let i = 0; i < countries.length; i++){
if (max < countries[i].length) {
max = countries[i].length;
maxi = i;
}
}
console.log(countries[maxi]);
// 10.question
let five = [];
for (const iterator of countries) {
if (iterator.length == 5) {
five.push(iterator);
}
}
console.log(five);
// 11.question
const webTechs = [
'HTML',
'CSS',
'JavaScript',
'React',
'Redux',
'Node',
'MongoDB'
];
max = 0;
maxi = 0;
for (let i = 0; i < webTechs.length; i++){
if (max < webTechs[i].length) {
max = webTechs[i].length;
maxi = i;
}
}
console.log(webTechs[maxi]);
// 12.question
newArr = [];
for (const iterator of webTechs) {
let temp = []
temp.push(iterator);
temp.push(iterator.length);
newArr.push(temp);
}
console.log(newArr);
// 13.question
const mernStack = ['MongoDB', 'Express', 'React', 'Node']
console.log(mernStack.join(','));
// 14.question
for (const iterator of webTechs) {
console.log(iterator);
}
// 15.question
let fruits = ['banana', 'orange', 'mango', 'lemon'];
let revFruit = [];
for (i = fruits.length-1; i >=0;i--) {
revFruit.push(fruits[i]);
}
fruits = [...revFruit]
console.log(fruits);
// 16.question
const fullStack = [
['HTML', 'CSS', 'JS', 'React'],
['Node', 'Express', 'MongoDB']
];
for (const iterator of fullStack) {
for (const i of iterator) {
console.log(i);
}
}

@ -0,0 +1,67 @@
// 1.question
const countries = [
'Albania',
'Bolivia',
'Canada',
'Denmark',
'Ethiopia',
'Finland',
'Germany',
'Hungary',
'Ireland',
'Japan',
'Kenya'
];
let contryCopy = [...countries];
// 2.question
let sortedCountires = countries.slice();
sortedCountires.sort();
console.log(sortedCountires);
// 3.question
const mernStack = ['MongoDB', 'Express', 'React', 'Node']
const webTechs = [
'HTML',
'CSS',
'JavaScript',
'React',
'Redux',
'Node',
'MongoDB'
];
mernStack.sort();
webTechs.sort();
// 4.question and 6.question
let conLand = [];
for (const iterator of countries) {
if (iterator.includes('land')) {
conLand.push(iterator)
}
}
console.log(conLand);
// 5.question and 7.question
let max = 0;
let maxi = 0;
let high = []
for (let i = 0; i < countries.length; i++){
if (max < countries[i].length) {
max = countries[i].length;
maxi = i;
}
}
high.push(countries[maxi]);
console.log(high);
// 8.question
let newc = []
for (const iterator of countries) {
if (iterator.length >= 2) {
newc.push(iterator)
}
}
console.log(newc);
// 9.question
newc = []
countries.reverse();
for (const iterator of countries) {
newc.push(iterator.toUpperCase())
}
console.log(newc);

@ -0,0 +1,71 @@
// 1.question
function fullName() {
console.log(`Satya surendra`);
}
fullName();
// 2.question
function fullName(fullName,lastName) {
return fullName + ' ' + lastName;
}
console.log(fullName('satya', 'surendra'));
// 3.question
function addNumbers(a, b) {
return a + b;
}
console.log(addNumbers(1, 2));
// 4.question
function areaOfRectangle(l,b) {
return l * b;
}
// 5.question
function perimeterOfRectangle(l, b) {
return 2(l + b);
}
// 6.question
function volumeOfRectPrism(l, b, h) {
return l * b * h;
}
// 7.question
function areaOfCircle(r) {
return 3.14 * r * r;
}
// 8.question
function circumOfCircle(r) {
return 2 * 3.14 * r;
}
// 9.question
function density(mass, volume) {
return mass / volume;
}
// 10.question
function speed(d, t) {
return d / t;
}
// 11.question
function weight(mass,gravity) {
return mass * gravity;
}
// 12.question
function convertCelsiusToFahrenheit(c) {
return (c * 9 / 5) + 32;
}
// 13.question
function IBM(weight, height) {
let ibm = weight / Math.pow(height, 2);
if (ibm < 18.5) {
console.log('Underweight');
} else if (ibm >= 18.5 && ibm < 24.9) {
console.log('Normal weight');
} else if (ibm >= 25 && ibm < 29.9) {
console.log('Overweight');
} else {
console.log(`Obese`);
}
}
// 14.question
// 15.question
function findMax(a, b, c) {
return Math.max(a, b, c);
}

@ -0,0 +1,163 @@
// 1.question
function solveLinEquation(a, b, c) {
return -a / b;
}
// 2.question
// function solveQuadratic(a,b,c) {
// return Math.sqrt(-b + 4 * a * c) / 2*a;
// }
// // console.log(solveQuadratic()) // {0}
// console.log(solveQuadratic(1, 4, 4)) // {-2}
// console.log(solveQuadratic(1, -1, -2)) // {2, -1}
// console.log(solveQuadratic(1, 7, 12)) // {-3, -4}
// console.log(solveQuadratic(1, 0, -4)) //{2, -2}
// console.log(solveQuadratic(1, -1, 0)) //{1, 0}
// 3.question
function printArray(arr) {
for (let i = 0; i < arr.length; i++){
console.log(arr[i]);
}
}
printArray([1, 2, 3, 4, 5]);
// 4.question
function showDateTime() {
let now = new Date();
let day = now.getDate(),
mon = now.getMonth(),
year = now.getFullYear(),
hrs = now.getHours(),
min = now.getMinutes();
console.log(`${day}/${mon}/${year} ${hrs}:${min}`);
}
// 5.question
function swap(a, b) {
let t;
t = a;
a = b;
b = t;
console.log(a,b);
}
swap(1, 2)
// 6.question
function reverseArray(arr) {
let rev = [];
for (let i = arr.length; i >= 0; i--){
rev.push(arr[i]);
}
return rev;
}
// 7.question
function capitalizeArray(arr) {
let newArray = arr.map((e) => {
return e[0].toUpperCase() + e.slice(1);
})
console.log(newArray);
}
// 8.question
let arr = [];
function addItem(item) {
return arr.push(item);
}
console.log(arr);
// 9.question
function removeItem(index) {
return arr.splice(index,1)
}
// 10.question
function sumOfNumbers(min, max) {
let sum = 0;
for (let i = min; i <= max; i++){
sum += i;
}
return sum;
}
// 11.question
function sumOfOdds(min, max) {
let sum = 0;
for (let i = min; i <= max; i++){
if (i % 2 !== 0) {
sum += i;
}
}
return sum;
}
// 12.question
function sumOfEven(min, max) {
let sum = 0;
for (let i = min; i <= max; i++){
if (i % 2 === 0) {
sum += i;
}
}
return sum;
}
// 13.question
function evensAndOdds(num) {
let evenCount = 0;
let oddCount = 0;
for (let i = min; i <= max; i++){
if (i % 2 === 0) {
evenCount++;
} else {
oddCount++;
}
}
console.log(`The number of odds are ${evenCount} \n The number of odds are ${oddCount}`);
}
// 14.question
function sum() {
let sum = 0
for (let i = 0; i < arguments.length - 1; i++){
sum += arguments[i];
}
console.log(sum);
}
// 15.question
function randomUserIp() {
let ip = [];
let i = 0;
for (let i = 0; i < 4; i++){
let rand = Math.floor(Math.random() * 255);
ip.push(rand);
}
return `${ip[i++]}.${ip[i++]}.${ip[i++]}.${ip[i++]}`;
}
// 16.question
function randomMacAddress() {
let hex = '0123456789abcdef';
let mac = [];
let i = 0;
for (let i = 0; i < 6; i++) {
let macAddress = '';
for (let j = 0; j < 2; j++){
let rand = Math.floor(Math.random() * hex.length);
macAddress = macAddress + hex[rand];
}
mac.push(macAddress);
}
return `${mac[i++]}:${mac[i++]}:${mac[i++]}:${mac[i++]}:${mac[i++]}:${mac[i++]}`
}
console.log(randomMacAddress());
// 17.question
function randomHexaNumberGenerator() {
let hexcode = '0123456789abcdef';
let hex = '';
for (let i = 0; i < 6; i++){
let rand = Math.floor(Math.random() * hexcode.length);
hex += hexcode[rand];
}
return '#' + hex;
}
console.log(randomHexaNumberGenerator());
// 18.question
function userIdGenerator() {
let idcode = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
let id = '';
for (let i = 0; i < 7; i++){
let rand = Math.floor(Math.random() * idcode.length);
id += idcode[rand];
}
return id;
}
console.log(userIdGenerator());

@ -0,0 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script>
let numChar = parseInt(prompt('Enter the number of charecters for id:',0));
let numId = parseInt(prompt('Enter the number of id :',0));
console.log(numChar,numId);
console.log( userIdGeneratedByUser(numChar,numId));
function userIdGeneratedByUser(Char,Id){
let id_s = [];
for(let i=0;i<Id;i++){
id_s.push(userIdGenerator(Char))
}
return id_s;
}
function userIdGenerator(Char) {
let idcode = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
let id = '';
for (let i = 0; i < numChar; i++) {
let rand = Math.floor(Math.random() * idcode.length);
id += idcode[rand];
}
return id;
}
</script>
</body>
</html>

@ -0,0 +1,22 @@
// 1.question
let dog = {};
// 2.question
console.log(dog);
// 3.question
dog.name = 'cesar';
dog.age = 4;
dog.color = 'gold';
dog.bark = function() {
return 'woof-woof'
};
// 4.question
let name = dog.name,
age = dog.age,
color = dog.color,
bark = dog.bark();
console.log(bark);
// 5.question
dog.breed = 'golden retriever';
dog.getDogInfo = function () {
return `${this.name} is an ${this.breed} and his age is ${this.age} and his color is ${this.color} he sound like ${this.bark()}`
}

@ -0,0 +1,101 @@
const users = {
Alex: {
email: 'alex@alex.com',
skills: ['HTML', 'CSS', 'JavaScript'],
age: 20,
isLoggedIn: false,
points: 30
},
Asab: {
email: 'asab@asab.com',
skills: ['HTML', 'CSS', 'JavaScript', 'Redux', 'MongoDB', 'Express', 'React', 'Node'],
age: 25,
isLoggedIn: false,
points: 50
},
Brook: {
email: 'daniel@daniel.com',
skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux'],
age: 30,
isLoggedIn: true,
points: 50
},
Daniel: {
email: 'daniel@alex.com',
skills: ['HTML', 'CSS', 'JavaScript', 'Python'],
age: 20,
isLoggedIn: false,
points: 40
},
John: {
email: 'john@john.com',
skills: ['HTML', 'CSS', 'JavaScript', 'React', 'Redux', 'Node.js'],
age: 20,
isLoggedIn: true,
points: 50
},
Thomas: {
email: 'thomas@thomas.com',
skills: ['HTML', 'CSS', 'JavaScript', 'React'],
age: 20,
isLoggedIn: false,
points: 40
},
Paul: {
email: 'paul@paul.com',
skills: ['HTML', 'CSS', 'JavaScript', 'MongoDB', 'Express', 'React', 'Node'],
age: 20,
isLoggedIn: false,
points: 40
}
}
// 1.question
let temp = [];
let keys = Object.keys(users);
for (const key in users) {
temp.push(users[key].skills.length);
}
let max = Math.max(...temp);
let index = temp.indexOf(max)
console.log(keys[index]);
// 2.question
let logcount = 0;
let pointcount = 0;
for (const key in users) {
if(users[key].isLoggedIn === true){
logcount++;
}
if (users[key].points >= 50) {
pointcount++;
}
}
console.log(`${logcount} and ${pointcount}`);
// 3.question
let MERN = ['MangoDB', 'Express', 'React', 'Node'];
let i = 0;
temp = [];
for (const key in users) {
i++;
let skills = users[key].skills;
skills.forEach(element => {
if (element === 'MongoDB' && element === 'Express' && element === 'React' && element === 'Node') {
temp.push(i);
console.log('hi');
}
});
}
console.log(temp);
// 4.question
users.satya = {
email: 'satya@satya.com',
skills: ['HTML', 'CSS', 'JavaScript'],
age: 20,
isLoggedIn: true,
points:10
}
console.log(users);
// 5.question
keys = Object.keys(users);
// 6.question
let values = Object.values(users);

@ -0,0 +1,158 @@
// 1.question
let personAccount = {
firstName: "satya",
lastName: "surendra",
incomes: 0,
expenses: 0,
totalIncome: function () {
return;
},
totalExpenses: function () {
return;
},
accountInfo: function () {
return `Name : ${this.firstName} ${this.lastName}\nIncome: ${this.incomes}\nExpense: ${this.expenses}`;
},
addIncome: function () {
return;
},
addExpense: function () {
return;
},
accountBalance: function () {
return;
},
};
console.log(personAccount.accountInfo());
let users = [
{
_id: "ab12ex",
username: "Alex",
email: "alex@alex.com",
password: "123123",
createdAt: "08/01/2020 9:00 AM",
isLoggedIn: false,
},
{
_id: "fg12cy",
username: "Asab",
email: "asab@asab.com",
password: "123456",
createdAt: "08/01/2020 9:30 AM",
isLoggedIn: true,
},
{
_id: "zwf8md",
username: "Brook",
email: "brook@brook.com",
password: "123111",
createdAt: "08/01/2020 9:45 AM",
isLoggedIn: true,
},
{
_id: "eefamr",
username: "Martha",
email: "martha@martha.com",
password: "123222",
createdAt: "08/01/2020 9:50 AM",
isLoggedIn: false,
},
{
_id: "ghderc",
username: "Thomas",
email: "thomas@thomas.com",
password: "123333",
createdAt: "08/01/2020 10:00 AM",
isLoggedIn: false,
},
];
const products = [
{
_id: "eedfcf",
name: "mobile phone",
description: "Huawei Honor",
price: 200,
ratings: [
{ userId: "fg12cy", rate: 5 },
{ userId: "zwf8md", rate: 4.5 },
],
likes: [],
},
{
_id: "aegfal",
name: "Laptop",
description: "MacPro: System Darwin",
price: 2500,
ratings: [],
likes: ["fg12cy"],
},
{
_id: "hedfcg",
name: "TV",
description: "Smart TV:Procaster",
price: 400,
ratings: [{ userId: "fg12cy", rate: 5 }],
likes: ["fg12cy"],
},
];
// 2.question
let signUp = (name) => {
let len = users.filter((user) => user.username === name).length;
if (len) {
console.log(`This user already exits `);
} else {
users.push({
_id: name,
username: name,
email: `${name}@${name}.com`,
password: `${name}`,
createdAt: new Date(),
isLoggedIn: true,
});
}
};
// 2.b.question
let signIn = (name, password) => {
let user = users.filter(
(user) => user.username === name && user.password === password
);
if (user.length) {
user.isLoggedIn = true;
console.log(`Login successful`);
} else {
console.log(`Invalid username or password`);
}
};
// 3.a.question
let rateProduct = (productId, userId, rate) => {
let product = products.find((p) => {
return p._id === productId;
});
product.ratings.push({
userId: userId,
rate: rate,
});
};
// 3.b.question
let avgRateing = (productId) => {
let product = products.find((p) => {
return p._id === productId;
});
let totalRate = 0;
product.ratings.forEach((p) => {
totalRate = p.rate + totalRate;
});
return totalRate / product.ratings.length;
};
Loading…
Cancel
Save