Series of operations in javascript assignment expert

Author: Harry

Hello friends, thanks for visiting my website. I am a Python programmer. I, with some other members, write blogs on this website based on Python and Programming. We are still in the growing phase that's why the website design is not so good and there are many other things that need to be corrected in this website but I hope all these things will happen someday. But, till then we will not stop ourselves from uploading more amazing articles. If you want to join us or have any queries, you can mail me at Thank you

Answer to Question #207550 in HTML/JavaScript Web Application for jayanth

Series of Operations

Given an array

  1. myArray of numbers, write a JS program to perform the following steps and log the result. Multiply each value with 9.
  2. Subtract 20 from each value.
  3. Multiply each value with 7.
  4. Log the values of the resulting array separated by a space.
  • The input will be a single line containing an array myArray
  • The output should be a single line with values separated by a space
  • Each value in the array must be a number

Sample Input

[ 12, 2, 2, 4, 1 ]

Sample Output

616 -14 -14 112 -77

"use strict";

process.stdin.resume();
process.stdin.setEncoding("utf-8");

let inputString = "";
let currentLine = 0;

process.stdin.on("data", (inputStdin) => {
    inputString += inputStdin;
});

process.stdin.on("end", (_) => {
    inputString = inputString.trim().split("\n").map((str) => str.trim());
    main();
});

function readLine() {
    return inputString[currentLine++];
}
/* Please do not modify anything above this line */

function main() {
    const nestedArray = JSON.parse(readLine());
 /* Write your code here */

    const resultArray = nestedArray.map(arr => {
        if ( arr.some(item => item % 2 === 0) ) {
            return arr.reduce( (acc, current) => acc * current )
        } else {
            return 0
        }
    });

    console.log(resultArray);
}
CALCULATE THE PRICE

SERIES OF OPERATIONS

myArray of numbers, write a JS program to perform the following steps and log the result.

Multiply each value with 9.

Subtract 20 from each value.

Multiply each value with 7.

Log the values of the resulting array separated by a space.

Input

The input will be a single line containing an array myArray

Output

The output should be a single line with values separated by a space

Constraints

Each value in the array must be a number

Sample Input

[ 12, 2, 2, 4, 1 ]

Sample Output

616 -14 -14 112 -77

"use strict";

process.stdin.resume();

process.stdin.on("data", (inputStdin) => {

  inputString += inputStdin;

});

process.stdin.on("end", (_) => {

  inputString = inputString.trim().split("\n").map((str) => str.trim());

  main();

});

function readLine() {

  return inputString[currentLine++];

}

function main() {

  const myArray = JSON.parse(readLine());

  /* Write your code here */

}


JavaScript Assignment Operators

Assignment operators assign values to JavaScript variables.

OperatorExampleSame As
= x = y x = y
+= x += y x = x + y
-= x -= y x = x - y
*= x *= y x = x * y
/= x /= y x = x / y
%= x %= y x = x % y
**= x **= y x = x ** y

The **= operator is a part of ECMAScript 2016.

It does not work in Internet Explorer 11 or earlier.

Shift Assignment Operators

OperatorExampleSame As
<<= x <<= y x = x << y
>>= x >>= y x = x >> y
>>>= x >>>= y x = x >>> y

Logical Assignment Operators

OperatorExampleSame As
&= x &= y x = x & y
^= x ^= y x = x ^ y
|= x |= y x = x | y

The = Operator

The = assignment operator assigns a value to a variable.


The += Operator

The += assignment operator adds a value to a variable.


The -= Operator

The -= assignment operator subtracts a value from a variable.


The *= Operator

The *= assignment operator multiplies a variable.


The /= Operator

The /= assignment divides a variable.


The %= Operator

The %= assignment operator assigns a remainder to a variable.



The <<= Operator

The <<= assignment operator left shifts a variable.


The >>= Operator

The >>= assignment operator right shifts a variable (signed).


The >>>= Operator

The >>>= assignment operator right shifts a variable (unsigned).


The &= Operator

The &= assignment operator ANDs a variable.


The != Operator

The != assignment operator ORs a variable.


Test Yourself With Exercises

Exercise:

Use the correct assignment operator that will result in x being 15 (same as x = x + y).

Start the Exercise



What are assignment operators in JavaScript?

An assignment operator assigns a value to its left operand based on the value of its right operand. The simple assignment operator is equal ( = ), which assigns the value of its right operand to its left operand. That is, x = f() is an assignment expression that assigns the value of f() to x .

How do you turn in your JavaScript assignment?

The Assignment operator is equal (=) which assigns the value of right-hand operand to its left-hand operand. That is if a = b assigns the value of b to a. ... JavaScript | Assignment operators..

What is the main purpose of JavaScript?

JavaScript is a scripting language that enables you to create dynamically updating content, control multimedia, animate images, and pretty much everything else.

What is JavaScript PDF?

JavaScript is a lightweight, interpreted programming language. It is designed for creating network-centric applications. It is complimentary to and integrated with Java. JavaScript is very easy to implement because it is integrated with HTML. It is open and cross-platform.