0% found this document useful (0 votes)
7 views7 pages

JavaScript 3-Fayl Tahlili

The document provides a comprehensive overview of various JavaScript functions demonstrating different functionalities such as addition, conditional operations, and loops. It includes examples of functions with default parameters, return values, and console logging of results. Additionally, it explores the use of loops and conditional statements to manipulate and calculate values based on user input.

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)
7 views7 pages

JavaScript 3-Fayl Tahlili

The document provides a comprehensive overview of various JavaScript functions demonstrating different functionalities such as addition, conditional operations, and loops. It includes examples of functions with default parameters, return values, and console logging of results. Additionally, it explores the use of loops and conditional statements to manipulate and calculate values based on user input.

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

Funksiya

Funksiya - maxsus vazifani bajaruvchi ko‘rsatmalar to‘plami. U o‘z nomiga ega va u


qiymatlarni (parametrlar) qabul qiladi va qiymat qaytaradi:
function addNums(num1, num2){
[Link](num1 + num2);
}
addNums(num1=5,num2=7)

function add(a, b) {
return a + b;
}
[Link](add(2, 3));

function test(a) {
a = a + 5;
}
let x = 10;
test(x);
[Link](test(x))
[Link](x);

[Link](sum(3,4));

function sum(a,b){
return a+b;
}

let x = 5;

function test() {
let x = 10;
return x;
}

[Link](test());
[Link](x);

let x = 3;

function test(a) {
a = a * 2;
return a;
}
[Link](test(x));
[Link](x);
function my_fun(n, m = 5){
var a = 0;
if (m > n) {
a = 3 * m + n;
} else {
a = 2 * n + m;
}
return a;
}
var x = my_fun(3, 5);
var y = my_fun(7);
var z = 3 * x + 4 * y;
[Link](z);

1.
function calc(a, b = 4) {
if (a > b) {
return a - b;
} else {
return a + b;
}
}
var p = calc(6, 3);
var q = calc(2);
var r = p * q;
[Link](r);

2.
function compute(x, y = 2) {
if (x % y === 0) {
return x / y;
} else {
return x * y;
}
}
var a = compute(8, 2);
var b = compute(5);
var c = a + b;
[Link](c);
3.
function sumDiff(m, n = 7) {
if (m < n) {
return n - m;
} else {
return m + n;
}
}
var x = sumDiff(10, 3);
var y = sumDiff(5);
var z = x - y;
[Link](z);

4.
function multiplyOrAdd(p, q = 6) {
if (p === q) {
return p * q;
} else {
return p + q;
}
}
var m = multiplyOrAdd(4, 4);
var n = multiplyOrAdd(3);
var result = m + n;
[Link](result);

5.
function fun1(a, b = 10) {
if (a % 2 === 0) {
return a + b;
} else {
return a - b;
}
}
var val1 = fun1(8, 5);
var val2 = fun1(7);
var total = val1 * val2;
[Link](total);
6.
function fun2(x, y = 3) {
if (x > 2 * y) {
return x - y;
} else {
return x + y;
}
}
var r1 = fun2(10, 4);
var r2 = fun2(5);
var final = r1 + 2 * r2;
[Link](final);

7.
function checkNum(n, m = 8) {
if (n < m) {
return 2 * n - m;
} else {
return n + 2 * m;
}
}
var s1 = checkNum(5, 10);
var s2 = checkNum(12);
var answer = s1 + s2;
[Link](answer);

8.
function funCalc(a, b = 9) {
if (a % 3 === 0) {
return a / 3 + b;
} else {
return a * 2 - b;
}
}
var x1 = funCalc(6, 5);
var x2 = funCalc(7);
var z1 = 2 * x1 + 3 * x2;
[Link](z1);
9. n=4 bo'lganda dastur natijasini aniqlang
let n = Number(prompt('n='));
let sum = 0;
for(let i = 1; i <= n; i++, n--){
sum += i;
if(i % 2 === 0){
continue;
}
sum += n;
}
[Link](sum); dastur natijasi qachon 7ga teng bo'ladi

10.
let m = Number(prompt('m='));
let total = 1;
for(let j = 1; j < m; j++, m--){
total += j;
if(j < 4){
continue;
}
total += m;
}
[Link](total);

11.
let x = Number(prompt('x='));
let result = 0;
for(let a = 1; a <= x; a++, x--){
result += x;
if(a % 2 !== 0){
continue;
}
result += a;
}
[Link](result);

12. n=3 bo'lganda dastur natijasini aniqlang.


let n = Number(prompt('n='));
let sum = 0;
for(let k = 1; k <= n; k++, n--){
sum += k;
if(k <= 2){
continue;
}
sum += n * 2;
}
[Link](sum);
13.
let p = Number(prompt('p='));
let s = 1;
for(let i = 1; i < p; i++, p--){
s += i;
if(i % 3 === 0){
continue;
}
s += p;
}
[Link](s);

14.
let n = Number(prompt('n='));
let total = 0;
for(let i = 1; i < n; i++, n--){
total += i * 2;
if(i < 5){
continue;
}
total += n;
}
[Link](total);

15.
let k = Number(prompt('k='));
let sum = 0;
for(let i = 1; i <= k; i++, k--){
sum += k - i;
if(i < 3){
continue;
}
sum += i * 2;
}
[Link](sum);

16.
let n = Number(prompt('n='));
let res = 0;
for(let i = 1; i < n; i++, n--){
res += i + n;
if(i % 2 === 1){
continue;
}
res += i;
}
[Link](res);
17.
let m = Number(prompt('m='));
let total = 1;
for(let j = 1; j <= m; j++, m--){
total += j;
if(j < 4){
continue;
}
total += j * m;
}
[Link](total);

You might also like