day-6 complete

pull/408/head
satya 3 years ago
parent 721a113a56
commit 00c9da92bb

@ -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);
Loading…
Cancel
Save