Page 385 - Web_Application_v2.0_C12_Fb
P. 385
document.getElementById("result").innerHTML += "Colors array as string: " +
colorsString + "<BR>";
colors.unshift("Purple");
document.getElementById("result").innerHTML += "Colors array after unshift():
" + colors.join(", ") + "<br>";
var colorsJoined = colors.join(", ");
document.getElementById("result").innerHTML += "Colors array joined into
string: " + colorsJoined + "<br>";
delete colors[1];
document.getElementById("result").innerHTML += "Colors array after delete: "
+ colors.join(", ") + "<br>";
var concatenatedArray = colors.concat(shapes);
document.getElementById("result").innerHTML += "Concatenated array: " +
concatenatedArray.join(", ") + "<br>";
}
</SCRIPT>
</BODY>
</HTML>
Output of the preceding code is as follows:
17. Write a JavaScript code to input x and y values of two points A and B. Calculate the distance between
the two points using the following formula:
Distance = (x − ) + (y − x y ) 2
2
2 1 2 1
Hint: Where the two pints are A(X , Y ) and B(X , Y ).
2
1
1
2
Ans. <!DOCTYPE html>
<HTML>
<HEAD>
<TITLE>Distance Calculator</TITLE>
</HEAD>
<BODY>
<H1>Distance Calculator</H1>
<P>Enter the x and y values of two points:</P>
<P>Point A:</P>
<INPUT TYPE="number" ID="x1" PLACEHOLDER="x1">
Practical Work 383

