110 likes | 320 Views
CSC318 – WEB APPLICATION DEVELOPMENT. BY: MUHD EIZAN SHAFIQ BIN ABD AZIZ FACULTY of COMPUTER and MATHEMATICAL SCIENCES. Outline. JavaScript Array & Objects. JavaScript Array JavaScript Objects JavaScript Math Object JavaScript Date & Time Object. Javascript Array. Array.
E N D
CSC318 – WEB APPLICATION DEVELOPMENT BY: MUHD EIZAN SHAFIQ BIN ABD AZIZ FACULTY of COMPUTER and MATHEMATICAL SCIENCES
Outline JavaScript Array & Objects • JavaScript Array • JavaScript Objects • JavaScript Math Object • JavaScript Date & Time Object FSKM UiTM Pahang Page 2
Javascript Array Array • What is an array? • Temporary (storage|memory) of similar data • Has 1 variable • Store a group of data • Text • Numbers • images FSKM UiTM Pahang Page 3
Array Javascript Array • Example <script type="text/javascript"> // declare an array var stud_name = new Array(); // assign values on stud_name array stud_name[0] = "Anwar"; stud_name[1] = "Azlin"; stud_name[2] = "Asmaa'"; stud_name[3] = "Ezatul Najwa"; stud_name[4] = "Fauziyah"; /* Another method var stud_name = new Array("anwar","azlin","asmaa"); */ </script> FSKM UiTM Pahang Page 4
JavaScript Objects Basic Object in JavaScript <script language="javascript"> // create js object var person = new Object(); // assign values to object properties person.fullname = "Harun Salim Bachik"; person.age = 45; person.gender = "Male"; </script> FSKM UiTM Pahang Page 5
JavaScript Objects JavaScript Math Object • JavaScript provides four mathematical functions. Some of them are: • random(): return a random number between 0 and 1 • round(): round a number to the nearest integer • max(x, y): return larger number between x and y • min(y, y): return smaller number between x and y • pow(x, y): return xy • To use all the functions, it must starts with Math.<math_function> FSKM UiTM Pahang Page 6
JavaScript Objects JavaScript Math Object <script type="text/javascript"> document.write(Math.random()); document.write("<br><br>"); document.write(Math.round(45.2)); document.write("<br><br>"); document.write("Max is: " + Math.max(14, 7)); document.write("<br><br>"); document.write("Min is: " + Math.min(14, 7)); document.write("<br><br>"); document.write("10<sup>10</sup>: " + Math.pow(10, 2)); </script> FSKM UiTM Pahang Page 7
JavaScript Objects Javascript Date & Time Object <script language="javascript"> var now = new Date(); var day = now.getDate(); var month = now.getMonth() + 1; var year = now.getYear(); if(year < 1000) year = year + 1900; var fullDate = day + "/" + month + "/" + year; document.write("Today's date is: " + fullDate); </script> FSKM UiTM Pahang Page 8
JavaScript Objects Javascript Date & Time Object <script language="javascript"> var now = new Date(); var hour = now.getHours(); var minute = now.getMinutes(); var second = now.getSeconds(); document.write("Current time is " + hour + ":"); document.write(minute + ":"); document.write(second); </script> FSKM UiTM Pahang Page 9
Question? FSKM UiTM Pahang Page 10
Knuckles (2001). Introduction to Interactive Programming on the Internet using HTML & Javascript. John Wiley & Sons, Inc. http://www.w3schools.com/js/default.asp http://www.javascriptkit.com/jsref/math.shtml Bibliography (Book) Bibliography (Website) FSKM UiTM Pahang Page 11