//範例─輸出:
document.write( x + "<br>");
document.write( "x的值是:" + x + "<br>");
//範例─條件判斷:
if ( x > 3 ) {
document.write( x + "大於3。<br>");
}
//範例─條件判斷(2層):
if ( x > 3 ) {
document.write( x + "大於3。<br>");
}else{
document.write( x + "小於或等於3。<br>");
}
//範例─條件判斷(3層):
if ( x > 3 ) {
document.write( x + "大於3。<br>");
}else if ( x == 3){
document.write( x + "等於3。<br>");
}else{
document.write( x + "小於3。<br>");
}
//範例─迴圈:
for (var i=0 ; i < x ; i++ ) {
document.write( "第" + i + "次。<br>");
}
//函數:
//函數名稱為「f1」,輸入「x」,輸出y為x的平方(2次方)
function f1(x){
var y = x * x ;
return y;
}
alert( f1(3) );
alert( f1(6) );
alert( f1(9) );
//函數:
//函數名稱為「f2」,輸入「x,y」,輸出z為x*y
function f2(x,y){
var z = x * y ;
return z;
}