Page 1 of 1

01. Copy & paste this code directly, then test the output. This code ALREADY WORKS, however it has not been written well

Posted: Fri Jul 08, 2022 6:16 am
by answerhappygod
01 Copy Paste This Code Directly Then Test The Output This Code Already Works However It Has Not Been Written Well 1
01 Copy Paste This Code Directly Then Test The Output This Code Already Works However It Has Not Been Written Well 1 (78.55 KiB) Viewed 22 times
var outputAreaRef =document.getElementById("outputArea3");var output = "";function flexible(fOperation, operand1, operand2){ var result = fOperation(operand1, operand2); return result;}output += flexible(function(num1, num2) {return num1 + num2}, 3, 5)+ "<br/>";output += flexible(function(num1, num2) {return num1 * num2}, 3, 5)+ "<br/>"; outputAreaRef.innerHTML = output;
01. Copy & paste this code directly, then test the output. This code ALREADY WORKS, however it has not been written well, because the functions can't be used anywhere else in the code. Look at lines 11 & 12, and replace the functions defined in-place, with proper named functions. 2 3 4 5 6 7 8 9 10 11 12 13 14 ∞ H var outputAreaRef = document.getElementById("outputArea3"); var output = ""; 8 15 function flexible (fOperation, operandl, operand2) { var result = foperation (operandl, operand2); return result; output += flexible (function (numl, num2) {return num1 + num2}, 3, 5) + "<br/>"; output += flexible (function (numl, num2) {return num1 * num2), 3, 5) + "<br/>"; Expected output: outputAreaRef.innerHTML = output;