DeveloperBreeze

Calculate Greatest Common Divisor (GCD) of Two Numbers

// Function to calculate the GCD of two numbers using the Euclidean Algorithm
function calculateGCD(a, b) {
    while (b !== 0) {
        const temp = b;
        b = a % b;
        a = temp;
    }
    return a;
}

// Calculate and log the GCD of two numbers (e.g., 48 and 18)
const gcd = calculateGCD(48, 18);
console.log('GCD of Two Numbers:', gcd);

Continue Reading

Discover more amazing content handpicked just for you

Tutorial
javascript

Running JavaScript in the Browser Console

  • Right-click on the webpage and select Inspect or press Ctrl+Shift+I.
  • Open the Console tab.
  • Go to Safari > Preferences > Advanced and enable the Show Develop menu in menu bar option.
  • Right-click on the webpage and select Inspect Element or press Cmd+Option+C.
  • Click on the Console tab.

Dec 10, 2024
Read More
Tutorial
javascript

Mastering console.log Advanced Usages and Techniques

You can log multiple values in a single console.log call by separating them with commas. This can be useful when you want to log related values together.

const name = 'John';
const age = 30;
console.log('Name:', name, 'Age:', age); // Output: Name: John Age: 30

Sep 02, 2024
Read More
Code
javascript

Parse JSON String to Object

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Validate Password Strength

// Function to check if a password meets certain strength criteria
function isValidPassword(password) {
    // Customize validation rules as needed
    const minLength = 8;
    const hasUppercase = /[A-Z]/.test(password);
    const hasLowercase = /[a-z]/.test(password);
    const hasDigit = /\d/.test(password);

    // Check if the password meets the criteria
    return password.length >= minLength && hasUppercase && hasLowercase && hasDigit;
}

// Example password
const password = 'SecurePwd123';

// Log whether the password is valid to the console
console.log('Is Valid Password:', isValidPassword(password));

Jan 26, 2024
Read More
Code
javascript

Convert Array of Objects to CSV

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Calculate Distance Between Two Points

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript

Detect Dark Mode Preference

// Check if the user prefers dark mode using window.matchMedia
const isDarkMode = window.matchMedia('(prefers-color-scheme: dark)').matches;

// Log whether dark mode is preferred by the user
console.log('Dark Mode:', isDarkMode);

Jan 26, 2024
Read More
Code
javascript

Detecting Browser and Version

No preview available for this content.

Jan 26, 2024
Read More
Code
javascript python +1

Generate Random Password

No preview available for this content.

Jan 26, 2024
Read More

Discussion 0

Please sign in to join the discussion.

No comments yet. Start the discussion!