Answer to Question #176316 in HTML/JavaScript Web Application for bhadra

Question #176316

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

plz provide the code of this program



1
Expert's answer
2021-03-28T08:05:34-0400

Create the file "Series ofOperations.html" and add the following code:




<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Series of Operations</title>
<script language="javascript" type="text/javascript">
    window.onload = function () {
        btnSubmit.addEventListener("click", displayResult);
        function displayResult() {
            if (txtNumbers.value != "") {
                var numbers = txtNumbers.value.split(",");
                var outputResult = "Multiply each value with 9:\n";
                for (var i = 0; i < numbers.length; ++i) {
                    numbers[i] *= 9;
                }
                outputResult += "[" + numbers.join(",") + "]\n";
                outputResult += "Subtract 20 from each value:\n";
                for (var i = 0; i < numbers.length; ++i) {
                    numbers[i] -= 20;
                }
                outputResult += "[" + numbers.join(",") + "]\n";
                outputResult += "Multiply each value with 7:\n";
                for (var i = 0; i < numbers.length; ++i) {
                    numbers[i] *= 7;
                }
                outputResult += "[" + numbers.join(",") + "]\n";


                txtResult.value = outputResult;
            } else {
                alert("Enter numbers!!!")
            }
        };
    }
    </script> 
</head>
<body>
	  <form>
		    Enter the values of array using comma. Example 12, 2, 2, 4, 1: <br />
            <input id="txtNumbers" type="text" value="">
            <input id="btnSubmit" type="button" value="Submit">
		  </p>
			<textarea id = "txtResult" rows = "10" cols = "50">
			</textarea>
        </form>
</body>
</html>




Example:


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS