JavaScript

出自維基百科,自由嘅百科全書
跳去: 定向搵嘢

JavaScript係一個由Netscape公司造嘅網站,基本上用啲簡單嘅程式語言。雖然係咁,用戶難免都要有一啲程式根底先可以用到JavaScript。之後佢交去ECMA做標準,變成ECMA-262,所以亦有人叫ECMAScript

演變[編輯]

網頁格式1990年代首次出現,嗰陣時嘅瀏覽器(Browser)只係可以辯認HTML語言,呢啲語言係用來話畀我哋知瀏覽器顯示咩資料,係靜態性嘅操作,Netscape Navigator 1.0就係呢個年代嘅瀏覽器。

Java同埋JavaScript[編輯]

Java同埋JavaScript完全係兩回事,但係兩個程式都好相似。

例子[編輯]

<script type="text/javascript"> var name=window.prompt("Enter your name"); document.write("Welcome,"+name); </script> </head> <script type="text/javascript"> var day=new Date(); var time=day.getHours(); if(time<12) { document.write("Good morning!"); }else{ document.write("Good afternoon!"); } </script>


Or

<script type="text/javascript"> var mark=prompt("What is your total marks?"); document.write("The grade of "+mark+" is"); if(mark>=90) document.write("A"); else if(mark>=80) document.write("B"); else if(mark>=70) document.write("C"); else if(mark>=60) document.write("D"); else if(mark>=50) document.write("E"); else document.write("F"); </script>


Or

<script type="text/javascript">

var total; //sum of grades var gradeCounter; //no. of grade counted var grade; //grade typed by user (as string) var gradeValue; //grade value(converted to integer) var average; //average of all grades

total=0;//clear total gradeCounter=1; while(gradeCounter<=10){ grade=window.prompt("Enter integer grade:","0"); gradeValue=parseInt( grade ); total=total+gradeValue; gradeCounter=gradeCounter+1; } average=total/10; document.writeln("The average is "+average); </script>


Or

<script> var i=1; for(i=1;i<1000000000000;i++){ document.write("Error Error Error Error Error Error Error Error Error Error
"); } </script>