Pertemuan 13 JavaScript
Boolean and Match Object Boolean Object Match Oject
Boolean <html> <body> <script type="text/javascript"> var b1=new Boolean( 0); var b2=new Boolean(1); var b3=new Boolean(""); var b4=new Boolean(null); var b5=new Boolean(NaN); var b6=new Boolean("false"); document.write("0 is boolean "+ b1 +"<br />"); document.write("1 is boolean "+ b2 +"<br />"); document.write("An empty string is boolean "+ b3 + "<br />"); document.write("null is boolean "+ b4+ "<br />"); document.write("NaN is boolean "+ b5 +"<br />"); document.write("The string 'false' is boolean "+ b6 +"<br />"); </script> </body> </html> 0 is boolean false 1 is boolean true An empty string is boolean false null is boolean false NaN is boolean false The string 'false' is boolean true
Match Object round() random() max() min()
round() 1 1 0 -4 -5 <html> <body> <script type="text/javascript"> document.write(Math.round(0.60) + "<br />"); document.write(Math.round(0.50) + "<br />"); document.write(Math.round(0.49) + "<br />"); document.write(Math.round(-4.40) + "<br />"); document.write(Math.round(-4.60)); </script> </body> </html>
random() <html> <body> <script type="text/javascript"> document.write(Math.random()); </script> </body> </html> 0.43995992964571484
max() <html> <body> <script type="text/javascript"> document.write(Math.max(5,7) + "<br />"); document.write(Math.max(-3,5) + "<br />"); document.write(Math.max(-3,-5) + "<br />"); document.write(Math.max(7.25,7.30)); </script> </body> </html> 7 5 -3 7.3
min() <html> <body> <script type="text/javascript"> document.write(Math.min(5,7) + "<br />"); document.write(Math.min(-3,5) + "<br />"); document.write(Math.min(-3,-5) + "<br />"); document.write(Math.min(7.25,7.30)); </script> </body> </html> 5 -3 -5 7.25
Tugas