0% found this document useful (0 votes)
5 views5 pages

JavaScript 4-Fayl Tahlili

The document contains a series of JavaScript code snippets that demonstrate various programming concepts such as loops, conditionals, and functions. Each snippet performs different calculations and outputs results to the console. The examples illustrate the use of control structures and function definitions in JavaScript.

Uploaded by

mrdmarimov
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views5 pages

JavaScript 4-Fayl Tahlili

The document contains a series of JavaScript code snippets that demonstrate various programming concepts such as loops, conditionals, and functions. Each snippet performs different calculations and outputs results to the console. The examples illustrate the use of control structures and function definitions in JavaScript.

Uploaded by

mrdmarimov
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

let n = 5;
let sum = 0;
let i = 1;
while(i <= n){
sum += i;
if(i % 2 === 0){
i++;
continue;
}
sum += n - i;
i++;
}
[Link](sum);

2.
let x = 4;
let total = 1;
let k = 0;
while(k < x){
k++;
total += k;
if(k > 3) {
total += k * 2;
}
}
[Link](total);

3.
let n = 6;
let s = 0;
for(let i = 1; i <= n; i++){
s += i;
if(i % 3 === 0){
continue;
}
s += i*i;
}
[Link](s);

4.
let m = 5;
let sum = 0;
let j = 1;
while(j <= m){
if(j % 2 !== 0){
sum += j;
} else {
sum += 2*j;
}
j++;
}
[Link](sum);
5.
let n = 7;
let res = 0;
for(let i = n; i > 0; i--){
res += i;
if(i % 2 === 1){
continue;
}
res += i/2;
}
[Link](res);

6.
let k = 6;
let total = 0;
let i = 1;
while(i <= k){
if(i < 4){
total += i;
i++;
continue;
}
total += i*3;
i++;
}
[Link](total);

7.
let n = 5;
let sum = 1;
for(let i = 1; i <= n; i++){
sum += i*2;
if(i % 2 === 0){
continue;
}
sum += i;
}
[Link](sum);

8.
let m = 6;
let result = 0;
let i = 1;
while(i <= m){
if(i % 3 === 0){
result += i*2;
} else {
result += i;
}
i++;
}
[Link](result);
9.
let n = 5;
let total = 0;
for(let i = 1; i <= n; i++){
total += i;
if(i > 2){
total += i*i;
}
}
[Link](total);

10.
let x = 10;
let sum = 0;
let i = 1;
while(i <= x){
if(i % 2 === 0){
sum += i*3;
} else {
sum += i;
}
if(sum > 50){
break;
}
i++;
}
[Link](sum);

11.
function hisobla(a, b, c = 2) {
var natija = 0;
if (a > b && a > c) {
natija = a + b + c;
} else if (b > c) {
natija = b * c;
} else {
natija = a * c;
}
return natija;
}
var x = hisobla(5, 3);
var y = hisobla(2, 4, 5);
[Link](x + y);
12.
function sonT(n, m) {
var k = n + m;
if (k > 10) {
if (n > m) {
k = k - 2;
} else {
k = k + 2;
}
} else {
k = k * 2;
}
return k;
}
var a = sonT(7, 5);
var b = sonT(3, 4);
[Link](a + b);

12.
function f(a, b = 2) {
if (a > b) return a - b;
return a + b;
}
[Link](f(5) + f(2, 5));

13.

function f(a, b) {

if (a === b) return a * b;

return a + b;

[Link](f(3, 3) + f(3, 4));

14.
function test4(x, y = 5) {
var z = 0;
if (x === y) {
z = x + y + 10;
} else {
z = x * 2;
}
return z;
}

var a = test4(5);
var b = test4(3, 4);
[Link](a + b);
15. function test6(a, b, c = 1) {
var natija = a;
if (b > a) {
natija = b + c;
} else {
natija = a - c;
}
return natija;
}

var x = test6(10, 5);


var y = test6(3, 7, 2);
[Link](x + y);

16. function test7(p1, p2 = 3) {


var k = 0;
if (p1 + p2 > 10) {
k = p1;
} else {
k = p1 * p2;
}
return k;
}

var m = test7(8, 4);


var n = test7(2);
[Link](m + n);

17. function f(a, b) {

if (a === b) return a * b;

return a + b;

[Link](f(3, 3) + f(3, 4));

[Link] test9(n, m, c = 4) {
var res = 0;
if (n > m) {
res = n + m;
} else if (m > c) {
res = m * c;
} else {
res = c - n;
}

return res;
}

var a = test9(2, 6); // c avtomatik 4 bo'ladi


var b = test9(8, 3, 5);
var jami = a + b;
[Link](jami);

You might also like