This content originally appeared on DEV Community and was authored by Islom Abdulakhatov
Functions
- #### Function Declaration
function log() {
console.log('Hello world')
}
log();
- #### Function Expression
const log = function () {
console.log('Hello world);
}
log();
- #### Arrow Function
const log = () => {
console.log('Hello world');
}
log()
const num1 = +prompt('num1: ', '');
const option = prompt('option(+;-;*;/: ', '')
const num2 = +prompt('num2: ', '');
function addition(num1, num2) {
console.log(num1 + num2)
}
function subtraction(num1, num2) {
console.log(num1 - num2)
}
function multiplication(num1, num2) {
console.log(num1 * num2)
}
function division(num1, num2) {
if (num2 === 0) {
console.log('Error: Division by zero is not allowed');
} else {
console.log(num1 / num2)
}
}
function result(num1, option, num2) {
console.log(num1, option, num2)
if(option === '+') {
addition(num1, num2);
}
if(option === '-') {
subtraction(num1, num2);
}
if(option === '*') {
multiplication(num1, num2);
}
if(option === '/') {
division(num1, num2);
}
if(option !== '+' || option !== '-' || option !== '*' || option !== '/' ) {
alert("Mavjud bo'lmagan amal! (+;-;*;/) shularni kiriting!");
}
}
result(num1, option, num2);
While Loop
while(condition) {
console.log(1);
}
- condition false bo'lmaguncha loop qayta qayta aylanadi
let count = 0;
while(count <= 10) {
console.log(count);
count++;
}
For loop
for(start, condition, increment) {
}
for(let i = 0; i < 10; i++) {
console.log(i)
}
This content originally appeared on DEV Community and was authored by Islom Abdulakhatov
Print
Share
Comment
Cite
Upload
Translate
Updates
There are no updates yet.
Click the Upload button above to add an update.
APA
MLA
Islom Abdulakhatov | Sciencx (2024-07-01T13:22:42+00:00) Functions. Retrieved from https://www.scien.cx/2024/07/01/functions/
" » Functions." Islom Abdulakhatov | Sciencx - Monday July 1, 2024, https://www.scien.cx/2024/07/01/functions/
HARVARDIslom Abdulakhatov | Sciencx Monday July 1, 2024 » Functions., viewed ,<https://www.scien.cx/2024/07/01/functions/>
VANCOUVERIslom Abdulakhatov | Sciencx - » Functions. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/07/01/functions/
CHICAGO" » Functions." Islom Abdulakhatov | Sciencx - Accessed . https://www.scien.cx/2024/07/01/functions/
IEEE" » Functions." Islom Abdulakhatov | Sciencx [Online]. Available: https://www.scien.cx/2024/07/01/functions/. [Accessed: ]
rf:citation » Functions | Islom Abdulakhatov | Sciencx | https://www.scien.cx/2024/07/01/functions/ |
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.