亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

JavaScript If...Else statement

JavaScript If...Else Statement

Conditional statements are used to perform different actions based on different conditions.

Conditional Statements

Usually when writing code, you always need to perform different actions for different decisions. You can use conditional statements in your code to accomplish this task.

In JavaScript, we can use the following conditional statements:

if statement - Use this statement to execute code only when the specified condition is true

if... else statement - execute code when the condition is true and other code when the condition is false

if...else if....else statement - use this statement to select one of multiple blocks of code to Execute

switch statement - Use this statement to select one of multiple blocks of code to execute

If statement

The statement will only be executed if the specified condition is true code.

Syntax

if (condition)
{
Code executed when the condition is true
}

Please use lowercase if. Using uppercase letters (IF) will generate a JavaScript error!

If...else statement

Please use the if...else statement to execute the code when the condition is true, and when the condition is Execute other code when false.

Grammar

if (condition)
  {
  當(dāng)條件為 true 時執(zhí)行的代碼
  }
else
  {
  當(dāng)條件不為 true 時執(zhí)行的代碼
  }
點(diǎn)擊這個按鈕,獲得基于時間的問候。點(diǎn)擊這里function myFunction(){
var x="";
var time=new Date().getHours();
if (time
Continuing Learning
||
<html> <body> <script type="text/javascript"> var d = new Date() var time = d.getHours() if (time < 10) { document.write("<b>早安</b>") } else { document.write("<b>祝您愉快</b>") } </script> <p>本例演示 If...Else 語句。</p> <p>如果瀏覽器時間小于 10,那么會向您問“早安”,否則會向您問候“祝您愉快”。</p> </body> </html>
submitReset Code