Page 349 - Webapplication11_C11_Flipbook
P. 349
document.write("<br>"+Math.floor(5.2))
document.write("<br>"+Math.floor(-5.2))
document.write("<br>"+Math.trunc(8.2))
document.write("<br>"+Math.trunc(-8.2))
</SCRIPT>
</BODY>
</HTML>
Output of the above code is as follows:
Lab Assignment ‘n Activity #Interdisciplinary
Check the output of the following code. Explain the output.
<html>
<body>
<h1>Studying JavaScript</h1>
<script>
document.write("Math.floor(-5.7): " + Math.floor(-5.7))
document.write("<br> Math.ceil(3.4): " + Math.ceil(3.4))
document.write("<br>"+isNaN("Three hundred"))
</script>
</body>
</html>
4.18 STRING OPERATIONS
You already know that concatenation is performed by placing a + sign between two strings. You can also use various
string methods in JavaScript to work with strings:
Method/ Description Example
Property
length Returns the string’s length. document.write(“Constantinople”.length)
Output: 14
substring It extracts the substring using the starting and ending str1 = “Pineapple is very tasty!”;
positions as parameters. If you leave the ending position document.write(str1.substring(7,20))
blank, the string will be extracted from beginning to Output: le is very ta
end.
JavaScript Part 1 347

