<!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>
Comments
Leave a comment