.ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻒﻠﺘﺨﻣ ﻂﯾﺍﺮﺷ ﺱﺎﺳﺍ ﺮﺑ ﻒﻠﺘﺨﻣ ﺕﺎﻣﺍﺪﻗﺍ ﻡﺎﺠﻧﺍ ﯼﺍﺮﺑ ﯽﻃﺮﺷ ﺕﺍﺭﻮﺘﺳﺩ
.ﺪﯿﻫﺩ ﻡﺎﺠﻧﺍ ﻒﻠﺘﺨﻣ ﯼﺎﻫ ﯼﺮﯿﮔ ﻢﯿﻤﺼﺗ ﯼﺍﺮﺑ ﺍﺭ ﯽﻔﻠﺘﺨﻣ ﺕﺎﻣﺍﺪﻗﺍ ﺪﯿﻫﺍﻮﺧ ﯽﻣ ،ﺪﯿﺴﯾﻮﻧ ﯽﻣ ﺪﮐ ﯽﺘﻗﻭ
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺩﻮﺧ ﺪﮐ ﺭﺩ ﯽﻃﺮﺷ ﺕﺍﺭﻮﺘﺳﺩ ﺯﺍ ﺪﯿﻧﺍﻮﺗ ﯽﻣ ﺭﺎﮐ ﻦﯾﺍ ﯼﺍﺮﺑ
:ﻢﯾﺭﺍﺩ ﺍﺭ ﺮﯾﺯ ﯽﻃﺮﺷ ﺕﺍﺭﺎﺒﻋ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺭﺩ
ﺪﺷﺎﺑ ﺖﺳﺭﺩ ﻩﺪﺷ ﺺﺨﺸﻣ ﻁﺮﺷ ﮏﯾ ﻪﮐ ﯽﺗﺭﻮﺻ ﺭﺩ ،ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺍﺮﺟﺍ ﯼﺍﺮﺑ ﺪﮐ ﮎﻮﻠﺑ ﮏﯾ ﻦﯿﯿﻌﺗ ﯼﺍﺮﺑ <
ﺪﺷﺎﺑ ﻥﺎﺴﮑﯾ ﻂﯾﺍﺮﺷ ﺮﮔﺍ ،ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺍﺮﺟﺍ ﯼﺍﺮﺑ ﺪﮐ ﺯﺍ ﮎﻮﻠﺑ ﮏﯾ ﻦﯿﯿﻌﺗ ﯼﺍﺮﺑ else if
.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺍﺮﺟﺍ ﯼﺍﺮﺑ ﺪﮐ ﻦﯾﺰﮕﯾﺎﺟ ﯼﺎﻫ ﮎﻮﻠﺑ ﺯﺍ ﯼﺭﺎﯿﺴﺑ ﻦﯿﯿﻌﺗ ﯼﺍﺮﺑ ﭻﯿﺋﻮﺳ<"code c
.ﺖﺳﺍ ﻩﺪﺷ ﻩﺩﺍﺩ ﺢﯿﺿﻮﺗ ﯼﺪﻌﺑ ﻞﺼﻓ ﺭﺩ switch
ﺕﺭﺎﺒﻋ
if
ﻪﯿﻧﺎﯿﺑ.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﺪﮐ ﺯﺍ ﯽﮐﻮﻠﺑ ﻦﯿﯿﻌﺗ ﯼﺍﺮﺑ if
if (condition) {
// block of code to be executed if the condition is true
}
.ﺪﻨﮐ ﯽﻣ ﺩﺎﺠﯾﺍ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯼﺎﻄﺧ ﮏﯾ (IF ﺎﯾ If) ﮒﺭﺰﺑ ﻑﻭﺮﺣ .ﺖﺳﺍ ﮏﭼﻮﮐ ﻑﻭﺮﺣ ﺎﺑ
ﺪﯾﺯﺎﺴﺑ «ﺮﯿﺨﺑ ﺯﻭﺭ» ﮏﯾﺮﺒﺗ ﮏﯾ ،ﺖﺳﺍ ﻥﺁ ﺯﺍ ﺮﺘﻤﮐ ﺖﻋﺎﺳ ﺮﮔﺍ
if (hour < 18) {
greeting = "Good day";
}
:ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﻦﯾﺍ ﯽﺳﺮﭙﻟﺍﻮﺣﺍ ﻪﺠﯿﺘﻧ
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript if</h2>
<p>Display "Good day!" if the hour is less than 18:00:</p>
<p id="demo">Good Evening!</p>
<script>
if (new Date().getHours() < 18) {
document.getElementById("demo").innerHTML = "Good day!";
}
</script>
</body>
</html>
else
ﺕﺭﺎﺒﻋ .ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺪﮐ ﮎﻮﻠﺑ ﻦﯿﯿﻌﺗ ﯼﺍﺮﺑ else
ﺕﺭﺎﺒﻋ ﺯﺍ
if (condition) {
// block of code to be executed if the condition is true
}
else {
// block of code to be executed if the condition is false
}
ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ "ﺏﻮﺧ ﺯﻭﺭ" ﮏﯾ ،ﺖﺳﺍ 18 ﺯﺍ ﺮﺘﻤﮐ ﺖﻋﺎﺳ ﺮﮔﺍ
if (hour < 18) {
greeting = "Good day";
}
else {
greeting = "Good evening";
}
:ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﻦﯾﺍ ﯽﺳﺮﭙﻟﺍﻮﺣﺍ ﻪﺠﯿﺘﻧ
→ ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript if .. else</h2>
<p>A time-based greeting:</p>
<p id="demo"></p>
<script>
const hour = new Date().getHours();
let greeting;
if (hour < 18) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
document.getElementById("demo").innerHTML = greeting;
</script>
</body>
</html>
else if
ﺕﺭﺎﺒﻋ.ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﻝﻭﺍ ﻁﺮﺷ ﻥﺩﻮﺑ ﺖﺳﺭﺩﺎﻧ ﺕﺭﻮﺻ ﺭﺩ ﺪﯾﺪﺟ ﻁﺮﺷ ﮏﯾ ﻦﯿﯿﻌﺗ ﯼﺍﺮﺑ ﺪﯿﻨﮐ ﺩﺎﺠﯾﺍ "ﺏﻮﺧ" ﮏﯾ ،ﺖﺳﺍ 10:00 ﺯﺍ ﺮﺘﻤﮐ ﻥﺎﻣﺯ ﺮﮔﺍ :ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﻦﯾﺍ ﯽﺳﺮﭙﻟﺍﻮﺣﺍ ﻪﺠﯿﺘﻧ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﯽﻓﺩﺎﺼﺗ ﮏﻨﯿﻟ ﻮﺤﻧ
if (condition1) {
// block of code to be executed if condition1 is true
}
else if (condition2) {
// block of code to be executed if the condition1 is false and condition2 is true
} else {
// block of code to be executed if the condition1 is false and condition2 is false
}
ﻝﺎﺜﻣ
if (time < 10) {
greeting = "Good morning";
}
else if (time < 20) {
greeting = "Good day";
}
else {
greeting = "Good evening";
}
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript if .. else</h2>
<p>A time-based greeting:</p>
<p id="demo"></p>
<script>
const time = new Date().getHours();
let greeting;
if (time < 10) {
greeting = "Good morning";
} else if (time < 20) {
greeting = "Good day";
} else {
greeting = "Good evening";
}
document.getElementById("demo").innerHTML = greeting;
</script>
</body>
</html>
ﺮﺘﺸﯿﺑ ﯼﺎﻫ ﻪﻧﻮﻤﻧ
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Math.random()</h2>
<p id="demo"></p>
<script>
let text;
if (Math.random() < 0.5) {
text = "<a href='https://w3schools.com'>Visit W3Schools</a>";
} else {
text = "<a href='https://wwf.org'>Visit WWF</a>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>