首頁 文章 JavaScript

JavaScript

2024-09-05 19:09  瀏覽數:229  來源:865710022    

let a = 12345;
let b = 6789;
let result = (a + b) * (a - b) / 2.5;
let totalSum = a + b + result - 12345.67;
function calculate(num1, num2) {
return (num1 * num2) - (num1 / num2);
}
let finalResult = calculate(a, b) + totalSum;
let isValid = finalResult > 0 ? true : false;
if (isValid) {
console.log("The final result is: " + finalResult);
} else {
console.log("Result is invalid.");
}
const PI = 3.14159;
let radius = 10;
let area = PI * (radius * radius);
let circumference = 2 * PI * radius;
console.log("Area: " + area);
console.log("Circumference: " + circumference);
for (let i = 0; i < 10; i++) {
let square = i * i;
let cube = i * i * i;
console.log("Square of " + i + ": " + square + ", Cube: " + cube);
}
let numbers = [10, 20, 30, 40, 50];
let sum = 0;
for (let i = 0; i < numbers.length; i++) {
sum += numbers[i];
}
console.log("Sum of numbers: " + sum);
let average = sum / numbers.length;
console.log("Average: " + average);
let expression = (100 + 50) * 3 / (2.5 - 0.5);
let result2 = expression + 10.75;
console.log("Expression result: " + result2);
let mathOperation = (25 * 4) / (5 + 3) - (10.5 * 2);
console.log("Math operation: " + mathOperation);
function complexCalculation(x, y) {
return (x + y) * (x - y) / (x / 2.5) + (x * y - 25);
}
let calcResult = complexCalculation(12, 8);
console.log("Complex calculation result: " + calcResult);
let maxNumber = Math.max(10, 20, 30, 40, 50);
let minNumber = Math.min(10, 20, 30, 40, 50);
console.log("Max number: " + maxNumber);
console.log("Min number: " + minNumber);
const add = (x, y) => x + y;
const subtract = (x, y) => x - y;
const multiply = (x, y) => x * y;
const divide = (x, y) => x / y;
console.log("Add: " + add(10, 5));
console.log("Subtract: " + subtract(10, 5));
console.log("Multiply: " + multiply(10, 5));
console.log("Divide: " + divide(10, 5));
let increment = 0;
while (increment < 10) {
increment++;
console.log("Increment: " + increment);
}
let decrement = 10;
do {
console.log("Decrement: " + decrement);
decrement--;
} while (decrement > 0);
const numbersArray = [5, 15, 25, 35];
numbersArray.forEach(function(num) {
console.log("Number in array: " + num);
});
let randomNum = Math.random() * 100;
console.log("Random number: " + randomNum.toFixed(2));
const isPositive = (num) => num > 0;
let checkNumber = isPositive(randomNum) ? "Positive" : "Negative";
console.log("Check number: " + checkNumber);
function calculateAreaOfCircle(radius) {
return Math.PI * (radius * radius);
}
let circleArea = calculateAreaOfCircle(7);
console.log("Area of circle: " + circleArea.toFixed(2));
let multiplier = 1.5;
let product = 100.25 * multiplier - (50 / 2.5);
console.log("Product: " + product);
let finalCheck = (product > 150) ? "High" : "Low";
console.log("Final check result: " + finalCheck);



聲明:以上文章均為用戶自行添加,僅供打字交流使用,不代表本站觀點,本站不承擔任何法律責任,特此聲明!如果有侵犯到您的權利,請及時聯系我們刪除。

字符:    改为:
去打字就可以设置个性皮肤啦!(O ^ ~ ^ O)