Skip to content

Skill-yards/JavaScript-Arithmetic_or_function

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

JavaScript-Arithmetic And Function

JavaScript Arithmetic Operations

In JavaScript, arithmetic operations allow you to perform basic mathematical calculations using operators. These operations are foundational in programming and are used to manipulate data, perform calculations, and create algorithms. Here’s an overview of the key arithmetic operations:

  1. Addition (+):

    • Combines two numbers to get their sum.
  2. Subtraction (-):

    • Finds the difference between two numbers by subtracting one from the other.
  3. Multiplication (*):

    • Multiplies two numbers to get their product.
  4. Division (/):

    • Divides one number by another to get the quotient.
  5. Modulus (%):

    • Returns the remainder of the division of one number by another.
  6. Increment (++):

    • Increases a number by one.
  7. Decrement (--):

    • Decreases a number by one.
  8. Order of Operations:

    • JavaScript follows the standard order of operations (PEMDAS: Parentheses, Exponents, Multiplication and Division (left-to-right), Addition and Subtraction (left-to-right)).

Task Questions:

Here are some questions focused on JavaScript arithmetic operations:

  1. Question 1: Write a JavaScript expression to add two numbers, a and b, and store the result in a variable sum. What will be the value of sum if a is 7 and b is 3?

  2. Question 2: Subtract the variable b from the variable a and store the result in a variable difference. What will be the value of difference if a is 15 and b is 8?

  3. Question 3: Multiply two numbers, a and b, and store the result in a variable product. What will be the value of product if a is 6 and b is 4?

  4. Question 4: Divide the variable a by the variable b and store the result in a variable quotient. What will be the value of quotient if a is 20 and b is 4?

  5. Question 5: Write an expression to find the remainder when a is divided by b and store it in a variable remainder. What will be the value of remainder if a is 10 and b is 3?

  6. Question 6: Write a JavaScript expression that first adds a and b, then multiplies the result by c. What will be the final result if a is 2, b is 3, and c is 4?

  7. Question 7: Create a JavaScript expression to calculate the average of three numbers a, b, and c. What will be the average if a is 5, b is 10, and c is 15?

  8. Question 8: Write an expression that increments the value of a by 1 and then multiplies it by b. What will be the result if a is 7 and b is 5?

JavaScript Functions

JavaScript functions are reusable blocks of code designed to perform a specific task. Functions take input, process it, and return a result. They help in organizing and reusing code efficiently. Here’s an overview of how functions work:

  1. Function Declaration:

    • A function is declared using the function keyword, followed by a name, parameters (optional), and a block of code.
    function functionName(parameter1, parameter2) {
        // Code to execute
    }
  2. Function Invocation:

    • Functions are called or invoked using their name followed by parentheses.
    functionName(argument1, argument2);
  3. Return Statement:

    • Functions can return a value using the return statement.
    function add(a, b) {
        return a + b;
    }

Task Questions:

Here are some questions related to JavaScript functions and arithmetic:

  1. Question 9: Write a function addNumbers that takes two parameters a and b, adds them, and returns the result. Call this function with the values 7 and 3. What will be the returned value?

  2. Question 10: Create a function subtractNumbers that takes two parameters a and b, subtracts b from a, and returns the result. Call this function with the values 15 and 8. What will the function return?

  3. Question 11: Define a function multiplyNumbers that multiplies two numbers passed as parameters. Call the function with 6 and 4. What will be the returned value?

  4. Question 12: Write a function divideNumbers that takes two parameters a and b and returns the quotient of a divided by b. Call this function with the values 20 and 4. What is the returned result?

  5. Question 13: Create a function calculateRemainder that accepts two parameters a and b, and returns the remainder when a is divided by b. What will be the result when you call the function with a = 10 and b = 3?

  6. Question 14: Write a function complexCalculation that adds two numbers a and b, multiplies the result by a third number c, and returns the final result. What will be the result of calling the function with a = 2, b = 3, and c = 4?

  7. Question 15: Define a function averageOfThree that takes three parameters a, b, and c, and returns their average. What is the result when the function is called with a = 5, b = 10, and c = 15?

  8. Question 16: Write a function incrementAndMultiply that takes two parameters a and b, increments a by 1, multiplies it by b, and returns the result. What will be the result of calling the function with a = 7 and b = 5?

  9. Question 17: Create a function power that takes two parameters base and exponent, and returns base raised to the power of exponent. What will be the result when base = 3 and exponent = 4?

  10. Question 18: Write a function isEven that takes a single parameter number and returns true if the number is even, and false if it is odd. Call this function with the value 12. What will be the returned value?

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published