.ﺩﻮﺷ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻒﻠﺘﺨﻣ ﻂﯾﺍﺮﺷ ﺱﺎﺳﺍ ﺮﺑ ﻒﻠﺘﺨﻣ ﺕﺎﻣﺍﺪﻗﺍ ﻡﺎﺠﻧﺍ ﯼﺍﺮﺑ .ﺪﯿﻨﮐ ﻩﺩﺎﻔﺘﺳﺍ ﺍﺮﺟﺍ ﯼﺍﺮﺑ ﺪﮐ ﯼﺎﻫ ﮎﻮﻠﺑ ﺯﺍ ﯼﺭﺎﯿﺴﺑ ﺯﺍ ﯽﮑﯾ ﺏﺎﺨﺘﻧﺍ ﯼﺍﺮﺑ :ﺪﻨﮑﯿﻣ ﺭﺎﮐ ﯼﺭﻮﺠﻨﯾﺍ .ﺩﻮﺷ ﯽﻣ ﯽﺑﺎﯾﺯﺭﺍ ﺭﺎﺑ ﮏﯾ ﭻﯿﺋﻮﺳ ﺕﺭﺎﺒﻋ .ﺩﻮﺷ ﯽﻣ ﻪﺴﯾﺎﻘﻣ ﺩﺭﻮﻣ ﺮﻫ ﺮﯾﺩﺎﻘﻣ ﺎﺑ ﺕﺭﺎﺒﻋ ﺭﺍﺪﻘﻣ .ﺩﻮﺷ ﯽﻣ ﺍﺮﺟﺍ ﻂﺒﺗﺮﻣ ﺪﮐ ﮎﻮﻠﺑ ،ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺩﻮﺟﻭ ﺖﻘﺑﺎﻄﻣ ﺮﮔﺍ .ﺩﻮﺷ ﯽﻣ ﺍﺮﺟﺍ ﺽﺮﻓ ﺶﯿﭘ ﺪﮐ ﮎﻮﻠﺑ ،ﺪﺷﺎﺑ ﻪﺘﺷﺍﺪﻧ ﺩﻮﺟﻭ ﺖﻘﺑﺎﻄﻣ ﺮﮔﺍ ﻦﯿﺑ ﯼﺩﺪﻋ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﻪﺘﻔﻫ ﺯﻭﺭ (.. 2=ﻪﺒﻨﺷ ﻪﺳ ،1=ﻪﺒﻨﺷﻭﺩ ،0=ﻪﺒﻨﺸﮑﯾ) :ﺪﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ ﻪﺘﻔﻫ ﺯﻭﺭ ﻡﺎﻧ ﻪﺒﺳﺎﺤﻣ ﯼﺍﺮﺑ ﻪﺘﻔﻫ ﺯﻭﺭ ﻩﺭﺎﻤﺷ ﺯﺍ ﻝﺎﺜﻣ ﻦﯾﺍ :ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﺯﻭﺭ ﻪﺠﯿﺘﻧ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﺪﯿﺳﺭ .ﺪﻨﮐ ﯽﻣ ﻒﻗﻮﺘﻣ ﺍﺭ ﭻﯿﺋﻮﺳ ﮎﻮﻠﺑ ﻞﺧﺍﺩ ﯼﺍﺮﺟﺍ ﺭﺎﮐ ﻦﯾﺍ .(ﺪﺳﺭ ﯽﻣ ﻥﺎﯾﺎﭘ ﻪﺑ) ﺩﻮﺷ ﯽﻣ ﻪﺘﺴﮑﺷ ﺎﺠﻧﺁ ﺭﺩ ﮎﻮﻠﺑ ﻝﺎﺣ ﺮﻫ ﻪﺑ .ﺖﺴﯿﻧ ﭻﯿﺋﻮﺳ ﮎﻮﻠﺑ ﺭﺩ ﺩﺭﻮﻣ ﻦﯾﺮﺧﺁ ﻪﺟﻮﺗ: ﺭﻮﺘﺳﺩ ﺮﮔﺍ break ﺮﮔﺍ ﯽﺘﺣ ﯼﺪﻌﺑ ﺩﺭﻮﻣ ،ﺪﯿﻨﮐ ﻑﺬﺣ ﺍﺭ .ﺩﻮﺷ ﺍﺮﺟﺍ ﺪﮐ ﺩﻮﺟﻭ ﻡﺪﻋ ﺕﺭﻮﺻ ﺭﺩ ﻪﮐ ﺪﻨﮐﯽﻣ ﺺﺨﺸﻣ ﺍﺭ ﯼﺪﮐ ﻦﯿﺑ ﯼﺩﺪﻋ ﻥﺍﻮﻨﻋ ﻪﺑ ﺍﺭ ﻪﺘﻔﻫ ﺯﻭﺭ :ﺪﯿﺴﯾﻮﻨﺑ ﺽﺮﻓ ﺶﯿﭘ ﻡﺎﯿﭘ ﮏﯾ ،ﺖﺳﺍ (0) ﻪﺒﻨﺸﮑﯾ ﻪﻧ ﻭ (6) ﻪﺒﻨﺷ ﻪﻧ ﺯﻭﺮﻣﺍ ﺮﮔﺍ :ﺩﻮﺑ ﺪﻫﺍﻮﺧ ﻦﺘﻣ ﻪﺠﯿﺘﻧ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﺷﺎﺑ ﭻﯿﺋﻮﺳ ﮏﯾ ﺭﺩ ﺩﺭﻮﻣ ﻦﯾﺮﺧﺁ ﺖﺴﯿﻧ ﻡﺯﻻ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺪﯿﻫﺩ ﻥﺎﯾﺎﭘ ﺖﺣﺍﺮﺘﺳﺍ ﮏﯾ ﺎﺑ ﺍﺭ ﺽﺮﻓﺶﯿﭘ ﻑﻭﺮﺣ ﻪﮐ ﺪﯿﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺩﺎﯾ ﻪﺑ ،ﺖﺴﯿﻧ ﭻﯿﺋﻮﺳ ﮎﻮﻠﺑ ﺪﯿﻫﺍﻮﺧ ﯽﻣ ﺕﻭﺎﻔﺘﻣ ﺕﺎﻗﻭﺍ ﯽﻫﺎﮔ ﺪﻧﺭﺍﺬﮔ ﯽﻣ ﮎﺍﺮﺘﺷﺍ ﻪﺑ 6 ﻭ 0 ﻭ ﺪﻧﺭﺍﺬﮔ ﯽﻣ ﮎﺍﺮﺘﺷﺍ ﻪﺑ ﺍﺭ ﯽﻧﺎﺴﮑﯾ ﺪﮐ ﮎﻮﻠﺑ 5 ﻭ 4 ،ﻝﺎﺜﻣ ﻦﯾﺍ ﺭﺩ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ .ﺩﻮﺷﯽﻣ ﺏﺎﺨﺘﻧﺍ ﻦﯿﻟﻭﺍ ﺩﺭﻮﻣ ،ﺪﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺖﻘﺑﺎﻄﻣ ﺩﺭﻮﻣ ﺭﺍﺪﻘﻣ ﺎﺑ ﺩﺭﻮﻣ .ﺪﻫﺩﯽﻣ ﻪﻣﺍﺩﺍ ﺽﺮﻓﺶﯿﭘ ﺐﺴﭼﺮﺑ ﻪﺑ ﻪﻣﺎﻧﺮﺑ ،ﺪﺸﻧ ﺖﻓﺎﯾ ﯽﻘﺒﻄﻨﻣ ﺩﺭﻮﻣ .ﺪﻫﺩﯽﻣ ﻪﻣﺍﺩﺍ ﭻﯿﺋﻮﺳ ﺯﺍ ﺲﭘ ﺕﺭﺎﺒﻋ ﻪﺑ ﻪﻣﺎﻧﺮﺑ ،ﺪﺸﻧ ﺖﻓﺎﯾ ﯽﺿﺮﻓﺶﯿﭘ .ﺪﻨﻨﮐ ﯽﻣ ﻩﺩﺎﻔﺘﺳﺍ (===) ﺖﺨﺳ ﻪﺴﯾﺎﻘﻣ ﺯﺍ ﭻﯿﺋﻮﺳ ﺩﺭﺍﻮﻣ .ﺪﻨﺷﺎﺑ ﻪﺘﺷﺍﺩ ﺖﻘﺑﺎﻄﻣ ﺎﺗ ﺪﻨﺷﺎﺑ ﻉﻮﻧ ﮏﯾ ﺯﺍ ﺪﯾﺎﺑ ﺮﯾﺩﺎﻘﻣ .ﺪﻨﺷﺎﺑ ﻉﻮﻧ ﮏﯾ ﺯﺍ ﺎﻫﺪﻧﻮﻠﻤﻋ ﻪﮐ ﺪﺷﺎﺑ ﺖﺳﺭﺩ ﺪﻧﺍﻮﺗ ﯽﻣ ﯽﻧﺎﻣﺯ ﺎﻬﻨﺗ ﻖﯿﻗﺩ ﻪﺴﯾﺎﻘﻣ ﮏﯾ :ﺖﺷﺍﺩ ﺪﻫﺍﻮﺨﻧ ﺩﻮﺟﻭ x ﯼﺍﺮﺑ ﯽﻘﯿﺒﻄﺗ ﭻﯿﻫ ﻝﺎﺜﻣ ﻦﯾﺍ ﺭﺩ → ﺪﯿﻨﮐ ﻥﺎﺤﺘﻣﺍ ﺍﺭ ﻥﺁ ﻥﺎﺗﺩﻮﺧ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ
ﭻﯿﺋﻮﺳ
ﻪﯿﻧﺎﯿﺑ
ﻮﺤﻧ
switch(expression) {
case x:
// code block
break;
case y:
// code block
break;
default:
// code block
}
ﻝﺎﺜﻣ
getDay()
ﺵﻭﺭswitch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript switch</h2>
<p id="demo"></p>
<script>
let day;
switch (new Date().getDay()) {
case 0:
day = "Sunday";
break;
case 1:
day = "Monday";
break;
case 2:
day = "Tuesday";
break;
case 3:
day = "Wednesday";
break;
case 4:
day = "Thursday";
break;
case 5:
day = "Friday";
break;
case 6:
day = "Saturday";
}
document.getElementById("demo").innerHTML = "Today is " + day;
</script>
</body>
</html>
ﻦﺘﺴﮑﺷ
ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ
ﺖﺴﮑﺷ<"code class="w3-codespan> ﮏﯾ ﻪﺑ ﺖﭙﯾﺮﮑﺳﺍ ﺍﻭﺎﺟ ﯽﺘﻗﻭ
ﺽﺮﻓ ﺶﯿﭘ
ﯼﺪﯿﻠﮐ ﻪﻤﻠﮐ
ﺽﺮﻓﺶﯿﭘ<"code clas
ﻝﺎﺜﻣ
getDay()
ﺵﻭﺭswitch (new Date().getDay()) {
case 6:
text = "Today is Saturday";
break;
case 0:
text = "Today is Sunday";
break;
default:
text = "Looking forward to the Weekend";
}
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript switch</h2>
<p id="demo"></p>
<script>
let text;
switch (new Date().getDay()) {
case 6:
text = "Today is Saturday";
break;
case 0:
text = "Today is Sunday";
break;
default:
text = "Looking forward to the Weekend";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
ﺽﺮﻓﺶﯿﭘ<"code class="w3-codespan> ﺩﺭ
ﻝﺎﺜﻣ
switch (new Date().getDay()) {
default:
text = "Looking forward to the Weekend";
break;
case 6:
text = "Today is Saturday";
break;
case 0:
text = "Today is Sunday";
}
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript switch</h2>
<p id="demo"></p>
<script>
let text;
switch (new Date().getDay()) {
default:
text = "Looking forward to the Weekend";
break;
case 6:
text = "Today is Saturday";
break;
case 0:
text = "Today is Sunday";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
ﺞﯾﺍﺭ ﺪﮐ ﯼﺎﻫ ﮎﻮﻠﺑ
ﻝﺎﺜﻣ
switch (new Date().getDay()) {
case 4:
case 5:
text = "Soon it is Weekend";
break;
case 0:
case 6:
text = "It is Weekend";
break;
default:
text = "Looking forward to the Weekend";
}
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript switch</h2>
<p id="demo"></p>
<script>
let text;
switch (new Date().getDay()) {
case 4:
case 5:
text = "Soon it is Weekend";
break;
case 0:
case 6:
text = "It is Weekend";
break;
default:
text = "Looking forward to the Weekend";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
ﺕﺎﯿﺋﺰﺟ ﺮﯿﯿﻐﺗ
ﻖﯿﻗﺩ ﻪﺴﯾﺎﻘﻣ
ﻝﺎﺜﻣ
let x = "0";
switch (x) {
case 0:
text = "Off";
break;
case 1:
text = "On";
break;
default:
text = "No value found";
}
<!DOCTYPE html>
<html>
<body>
<h2>JavaScript switch</h2>
<p id="demo"></p>
<script>
let x = "0";
switch (x) {
case 0:
text = "Off";
break;
case 1:
text = "On";
break;
default:
text = "No value found";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>