Page 383 - Web_Application_v2.0_C12_Fb
P. 383
document.getElementById("RESULT").textContent = "The array is: " + numbers +
" \n Sum of numbers: " + sum;
}
</SCRIPT>
</HEAD>
<BODY>
<H1>SUM OF NUMBERS</H1>
<BUTTON ONCLICK="calculateSum()">CLICK TO CALCULATE SUM</BUTTON>
<P ID="RESULT"></P>
</BODY>
</HTML>
Output of the preceding code is as follows:
15. Create a JavaScript function that will delete the last element and show the name in uppercase from an
array arr1 that was passed to it as an argument.
Ans. <!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>Delete Last Element and Uppercase</TITLE>
</HEAD>
<BODY>
<H2>Delete Last Element and Uppercase</H2>
<PRE>
<SCRIPT>
function processarray(arr1){
document.writeln("Original array: "+arr1+"")
var removedelement=arr1.pop()
var uppercaseelement=removedelement.toUpperCase()
document.writeln("Removed element: "+uppercaseelement+"")
document.writeln("Updated array: "+arr1)
}
var arr1=["john","peter","david"]
Practical Work 381

