1. 程式人生 > >js 學習之路6: if...else...條件語句的使用

js 學習之路6: if...else...條件語句的使用

var type set body doc 1.2 http class ont

1.1

if (...)

{

...

}

else

{

...

}

<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body>

<script charset = "utf-8">

function myfunction(){
    var x = 11;
    var y = x % 2;
    document.write(y + "<br>");
    if (x % 2 == 1){
        document.write(
"單數"); } else { document.write("雙數"); } } myfunction(); </script> </body> </html>

1.2

if (條件1)

{

...

}

else if (條件2)

{

...

}

else

{

...

}

<!DOCTYPE html>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<body>

<script charset = "utf-8">

function
myfunction(x){ var y = x % 2; if (x % 2 == 0){ document.write("雙數"); } else if (x > 10) { document.write("大於10的單數"); } else { document.write("普通單數"); } document.write("<br>"); document.write(x); } myfunction(15); </script> </body> </html>

js 學習之路6: if...else...條件語句的使用