{"id":1568,"date":"2020-11-13T20:22:30","date_gmt":"2020-11-13T16:52:30","guid":{"rendered":"https:\/\/behnudi.ir\/?p=1568"},"modified":"2024-09-04T11:55:13","modified_gmt":"2024-09-04T08:25:13","slug":"js07-conditions2","status":"publish","type":"post","link":"https:\/\/behnudi.ir\/?p=1568","title":{"rendered":"\u062c\u0627\u0648\u0627\u0633\u06a9\u0631\u06cc\u067e\u062a: \u06f7- \u06a9\u0627\u0646\u062f\u06cc\u0634\u0646 \u06f2"},"content":{"rendered":"<h2>\u0634\u0631\u0637 &#8211; Conditions<\/h2>\n<p>\u062f\u0631 \u062c\u0627\u0648\u0627\u0633\u06a9\u0631\u06cc\u067e\u062a \u0634\u0631\u0637 \u0631\u0627 \u0628\u0647 \u0633\u0647 \u06af\u0648\u0646\u0647 \u0645\u06cc\u200c\u062a\u0648\u0627\u0646 \u0646\u0648\u0634\u062a.<\/p>\n<ul>\n<li>?<\/li>\n<li>if<\/li>\n<li>Switch<\/li>\n<\/ul>\n<p>\u0647\u0645\u0647 \u0622\u0646\u0647\u0627 \u0631\u0627 \u0628\u0627\u06cc\u062f \u06cc\u0627\u062f \u06af\u0631\u0641\u062a \u0648 \u062f\u0631 \u0647\u0631 \u062c\u0627\u06cc\u06cc \u0622\u0646 \u0631\u0648\u0634\u06cc \u0631\u0627 \u06a9\u0647 \u0633\u0627\u062f\u0647\u200c\u062a\u0631 \u0627\u0633\u062a\u060c \u0628\u0647 \u06a9\u0627\u0631 \u0628\u0631\u062f.<\/p>\n<h3>\u0633\u0648\u0626\u06cc\u0686 &#8211; Switch<\/h3>\n<p>Switch \u062c\u0627\u06cc\u06af\u0632\u06cc\u0646 \u0686\u0646\u062f if \u0645\u06cc\u200c\u0634\u0648\u062f.<\/p>\n<pre><code class=\"javascript\">\r\n<mark>if<\/mark> (exp === val1) {\r\n\r\n    ...\r\n\r\n} <mark>else if<\/mark> (exp === val2) {\r\n\r\n    ...\r\n\r\n} <mark>else if<\/mark> (exp === val3) {\r\n\r\n    ...\r\n\r\n}\r\n\r\n...\r\n\r\n} <mark>else<\/mark> {\r\n    ...\r\n}\r\n\r\n<\/code><\/pre>\n<pre><code class=\"javascript\">\r\n<mark>switch<\/mark> (exp) {\r\n    <mark>case<\/mark> val1: \/\/ if (exp === val1)\r\n        ...\r\n        break;\r\n    \r\n    <mark>case<\/mark> val2: \/\/ if (exp === val2)\r\n        ...\r\n        break;\r\n\r\n    <mark>case<\/mark> val3: \/\/ if (exp === val3)\r\n        ...\r\n        break;\r\n\r\n    ...\r\n    \r\n    <mark>default<\/mark>: \/\/ else\r\n        ...\r\n    }\r\n\r\n<\/code><\/pre>\n<p>\u0627\u06af\u0631 break \u0631\u0627 \u0646\u0646\u0648\u06cc\u0633\u06cc\u062f\u060c \u06a9\u062f \u062a\u0627 break \u0628\u0639\u062f\u06cc \u0628\u062f\u0648\u0646 \u062a\u0648\u062c\u0647 \u0628\u0647 \u0634\u0631\u0637\u200c\u0647\u0627 \u0627\u062c\u0631\u0627 \u0645\u06cc\u200c\u0634\u0648\u062f.<\/p>\n<h4>\u0645\u062b\u0627\u0644<\/h4>\n<div class=\"code-header\">HTML<\/div>\n<pre><code class=\"html\">\r\n&lt;input type=\"text\" id=\"in-box\"&gt;\r\n&lt;button id=\"btn\"&gt;OK&lt;\/button&gt;        \r\n&lt;h1 id=\"out-box\"&gt;&lt;\/h1&gt;    \r\n\r\n<\/code><\/pre>\n<div class=\"code-header\">JS<\/div>\n<pre><code class=\"javascript\">\r\nconst inBox = document.getElementById(\"in-box\");\r\nconst outBox = document.getElementById(\"out-box\");\r\nconst btn = document.getElementById(\"btn\");\r\n\r\nbtn.onclick = function() {\r\n    let grade = inBox.value;\r\n    let msg; \r\n    switch (grade) {\r\n        case 'A':\r\n            msg = \"Excellent\";\r\n            break;\r\n        case 'B':\r\n            msg = \"Good\";\r\n            break;\r\n        case 'C':\r\n            msg = \"Fair\";\r\n            break;\r\n        case 'D':\r\n            msg = \"Poor\";\r\n            break;\r\n        case 'E':\r\n        case 'F':\r\n            msg = \"Failed\";\r\n            break;\r\n        default:\r\n            msg = \"Unknown grade\";\r\n    }\r\n    outBox.innerHTML = msg;\r\n}\r\n\r\n<\/code><\/pre>\n<p><iframe loading=\"lazy\" src=\"https:\/\/behnudi.ir\/f\/js1\/07\/01\" width=\"640\" height=\"360\"><\/iframe><\/p>\n<div>\n<h4>\u0645\u062b\u0627\u0644<\/h4>\n<\/div>\n<div class=\"code-header\">HTML<\/div>\n<pre><code class=\"html\">\r\n&lt;input type=\"text\" id=\"in-box\"&gt;\r\n&lt;button id=\"btn\"&gt;OK&lt;\/button&gt;        \r\n&lt;h1 id=\"out-box\"&gt;&lt;\/h1&gt;    \r\n\r\n<\/code><\/pre>\n<div class=\"code-header\">JS<\/div>\n<pre><code class=\"javascript\">\r\nconst inBox = document.getElementById(\"in-box\");\r\nconst outBox = document.getElementById(\"out-box\");\r\nconst btn = document.getElementById(\"btn\");\r\n\r\nbtn.onclick = function() {\r\n    let point = inBox.value;\r\n    let msg; \r\n    switch (true) {\r\n        case point &gt; 100 || point &lt; 0:\r\n            msg = \"Out of range\";\r\n            break;\r\n        case point &gt;= 90:\r\n            msg = \"Excellent\";\r\n            break;\r\n        case point &gt;= 80:\r\n            msg = \"Good\";\r\n            break;\r\n        case point &gt;= 70:\r\n            msg = \"Fair\";\r\n            break;\r\n        case point &gt;= 60:\r\n            msg = \"Poor\";\r\n            break;\r\n        case point &gt;= 0:\r\n            msg = \"Failed\";\r\n            break;\r\n        default:\r\n            msg = \"Not a number\";\r\n    }\r\n    outBox.innerHTML = msg;\r\n}\r\n\r\n<\/code><\/pre>\n<p><iframe loading=\"lazy\" src=\"https:\/\/behnudi.ir\/f\/js1\/07\/02\" width=\"640\" height=\"360\"><\/iframe><\/p>\n<h4>\u062a\u0645\u0631\u06cc\u0646 \u06f1<\/h4>\n<ul>\n<li>\u0627\u06cc\u0646 <a href=\"https:\/\/behnudi.ir\/f\/js1\/07\/07-1.zip\">\u0641\u0627\u06cc\u0644<\/a>\u00a0\u0631\u0627 \u062f\u0627\u0646\u0644\u0648\u062f \u06a9\u0646\u06cc\u062f.<\/li>\n<li>\u0622\u0646 \u0631\u0627 \u062f\u0631 \u0641\u0648\u0644\u062f\u0631 js1 \u0628\u0627\u0632 \u06a9\u0646\u06cc\u062f.<\/li>\n<li>\u062a\u0646\u0647\u0627 \u0641\u0627\u06cc\u0644 script.js \u0631\u0627 \u0645\u06cc\u200c\u062a\u0648\u0627\u0646\u06cc\u062f \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0647\u06cc\u062f.<\/li>\n<li>\u0627\u0633\u06a9\u0631\u06cc\u067e\u062a\u06cc \u0628\u0646\u0648\u06cc\u0633\u06cc\u062f \u062a\u0627 \u0645\u062b\u0644 \u0648\u06cc\u062f\u06cc\u0648\u06cc \u0632\u06cc\u0631 \u0639\u0645\u0644 \u06a9\u0646\u062f.<\/li>\n<\/ul>\n<p><video controls=\"controls\" width=\"300\"><source src=\"https:\/\/behnudi.ir\/f\/js1\/07\/img\/07-1.mp4\" type=\"video\/mp4\" \/>Your browser does not support the video tag.<\/video><\/p>\n<h4>\u062a\u0645\u0631\u06cc\u0646 \u06f2<\/h4>\n<ul>\n<li>\u0627\u06cc\u0646 <a href=\"https:\/\/behnudi.ir\/f\/js1\/07\/07-2.zip\">\u0641\u0627\u06cc\u0644<\/a>\u00a0\u0631\u0627 \u062f\u0627\u0646\u0644\u0648\u062f \u06a9\u0646\u06cc\u062f.<\/li>\n<li>\u0622\u0646 \u0631\u0627 \u062f\u0631 \u0641\u0648\u0644\u062f\u0631 js1 \u0628\u0627\u0632 \u06a9\u0646\u06cc\u062f.<\/li>\n<li>\u062a\u0646\u0647\u0627 \u0641\u0627\u06cc\u0644 script.js \u0631\u0627 \u0645\u06cc\u200c\u062a\u0648\u0627\u0646\u06cc\u062f \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0647\u06cc\u062f.<\/li>\n<li>\u0627\u0633\u06a9\u0631\u06cc\u067e\u062a\u06cc \u0628\u0646\u0648\u06cc\u0633\u06cc\u062f \u062a\u0627 \u0645\u0627\u0646\u0646\u062f \u06cc\u06a9 \u0645\u0627\u0634\u06cc\u0646 \u062d\u0633\u0627\u0628 \u06a9\u0627\u0631 \u06a9\u0646\u062f.<\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-847\" src=\"https:\/\/behnudi.ir\/f\/js1\/07\/img\/07-2.png\" \/><\/p>\n<hr \/>\n<p><video controls=\"controls\"><source src=\"https:\/\/behnudi.ir\/f\/js1\/07\/js1071.mp4\" type=\"video\/mp4\" \/>Your browser does not support the video tag.<\/video><\/p>\n<hr \/>\n<h3><mark>String<\/mark><\/h3>\n<p>\u0622\u0628\u062c\u06a9\u062a String \u0628\u0627 \u0645\u0642\u0627\u062f\u06cc\u0631 \u0627\u0633\u062a\u0631\u06cc\u0646\u06af \u06a9\u0627\u0631 \u0645\u06cc\u200c\u06a9\u0646\u062f.<\/p>\n<h4 dir=\"ltr\">String.<mark>length<\/mark><\/h4>\n<p>\u062a\u0639\u062f\u0627\u062f \u06a9\u0627\u0631\u0627\u06a9\u062a\u0631\u0647\u0627\u06cc \u0627\u0633\u062a\u0631\u06cc\u0646\u06af \u0631\u0627 \u0628\u0631\u0645\u06cc\u200c\u06af\u0631\u062f\u0627\u0646\u062f<\/p>\n<pre><code class=\"javascript\">\r\ns = \"Nikparvar High School\";\r\n\r\nl = s.length;        \/\/ l = 21\r\n\/\/-------------------------------------\r\nn = 20;\r\n\r\nl = n.length;        \/\/ l = undefined\r\n\/\/-------------------------------------\r\nb = true;\r\n\r\nl = b.length;        \/\/ l = undefined\r\n\r\n<\/code><\/pre>\n<h4 dir=\"ltr\">String.<mark>trim( )<\/mark><\/h4>\n<p>\u0641\u0636\u0627\u06cc \u062e\u0627\u0644\u06cc \u062f\u0648 \u0637\u0631\u0641 \u0627\u0633\u062a\u0631\u06cc\u0646\u06af \u0631\u0627 \u062d\u0630\u0641 \u0645\u06cc\u200c\u06a9\u0646\u062f.<\/p>\n<ul>\n<li>\u0627\u0641\u0642\u06cc: space, tab<\/li>\n<li>\u0639\u0645\u0648\u062f\u06cc: LF, CR<\/li>\n<\/ul>\n<h4 dir=\"ltr\">String.<mark>trim( )<\/mark><\/h4>\n<pre><code class=\"javascript\">\r\ns = \"      Nikparvar\";\r\n\r\nt = s.trim();        \/\/ t = \"Nikparvar\"\r\n\/\/-------------------------------------\r\ns = \"Nikparvar      \";\r\n\r\nt = s.trim();        \/\/ t = \"Nikparvar\"\r\n\/\/-------------------------------------\r\ns = \"   Nikparvar   \";\r\n\r\nt = s.trim();        \/\/ t = \"Nikparvar\"\r\n\/\/-------------------------------------\r\ns = `\r\nNikparvar\r\nHigh\r\nSchool`;\r\n\r\nt = s.trim();        \/\/ t = `Nikparvar\r\n                     \/\/      High\r\n                     \/\/      School`  \r\n\r\n<\/code><\/pre>\n<h4 dir=\"ltr\">String.<mark>substr(start, length)<\/mark><\/h4>\n<p>\u0628\u062e\u0634\u06cc \u0627\u0632 \u0627\u0633\u062a\u0631\u06cc\u0646\u06af \u0631\u0627 \u0628\u0631\u0645\u06cc\u200c\u06af\u0631\u062f\u0627\u0646\u062f.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-1107\" src=\"https:\/\/behnudi.ir\/f\/js1\/07\/img\/substring.png\" \/><\/p>\n<ul>\n<li>\u0634\u0645\u0627\u0631\u0634 \u06a9\u0627\u0631\u0627\u06a9\u062a\u0631\u0647\u0627 \u0627\u0632 \u0639\u062f\u062f \u0635\u0641\u0631 \u0622\u063a\u0627\u0632 \u0645\u06cc\u200c\u0634\u0648\u062f.<\/li>\n<li>\u0627\u0639\u062f\u0627\u062f \u0645\u0646\u0641\u06cc \u0627\u0632 \u0627\u0646\u062a\u0647\u0627 \u0634\u0645\u0631\u062f\u0647 \u0645\u06cc\u200c\u0634\u0648\u062f.<\/li>\n<\/ul>\n<pre><code class=\"javascript\">\r\ns = \"Nikparvar High School\";\r\n\r\nt = s.substr(0,3);         \/\/ t = \"Nik\"\r\n\r\nt = s.substr(-4,3);        \/\/ t = \"hoo\"\r\n\r\nt = s.substr(25,1);        \/\/ t = \"\"\r\n\r\nt = s.substr(5,-1);        \/\/ t = \"\"\r\n\r\n<\/code><\/pre>\n<h4 dir=\"ltr\">String.<mark>search(str)<\/mark><\/h4>\n<p>\u062c\u0627\u06cc str \u0631\u0627 \u062f\u0631 \u0645\u06cc\u0627\u0646 \u0627\u0633\u062a\u0631\u06cc\u0646\u06af \u0645\u0634\u062e\u0635 \u0645\u06cc\u200c\u06a9\u0646\u062f.<\/p>\n<pre><code class=\"javascript\">\r\ns = \"Nikparvar\";\r\n\r\np = s.search(\"Nik\");         \/\/ p = 0\r\n\r\np = s.search(\"nik\");         \/\/ p = -1\r\n\r\np = s.search(\"a\");           \/\/ p = 4\r\n\r\n<\/code><\/pre>\n<h4 dir=\"ltr\">String.<mark>replace(str1,str2)<\/mark><\/h4>\n<p>str1 \u0631\u0627 \u0628\u0627 str2 \u062c\u0627\u06cc\u06af\u0632\u06cc\u0646 \u0645\u06cc\u200c\u06a9\u0646\u062f.<\/p>\n<pre><code class=\"javascript\">\r\ns = \"Nikparvar\";\r\n\r\nnew = s.replace(\"Nik\", \"nik\");         \/\/ new = \"nikparvar\"\r\n\r\nnew = s.replace(\"a\", \"_\");             \/\/ new = \"Nikp_rvar\"\r\n\r\nnew = s.replace(\"M\", \"_\");             \/\/ new = \"Nikparvar\"\r\n\r\n<\/code><\/pre>\n<hr \/>\n<p><video controls=\"controls\"><source src=\"https:\/\/behnudi.ir\/f\/js1\/07\/js1072.mp4\" type=\"video\/mp4\" \/>Your browser does not support the video tag.<\/video><\/p>\n<hr \/>\n<h4>\u062a\u0645\u0631\u06cc\u0646 \u06f3<\/h4>\n<ul>\n<li>\u0627\u06cc\u0646 <a href=\"https:\/\/behnudi.ir\/f\/js1\/07\/07-3.zip\">\u0641\u0627\u06cc\u0644<\/a>\u00a0\u0631\u0627 \u062f\u0627\u0646\u0644\u0648\u062f \u06a9\u0646\u06cc\u062f.<\/li>\n<li>\u0622\u0646 \u0631\u0627 \u062f\u0631 \u0641\u0648\u0644\u062f\u0631 js1 \u0628\u0627\u0632 \u06a9\u0646\u06cc\u062f.<\/li>\n<li>\u062a\u0646\u0647\u0627 \u0641\u0627\u06cc\u0644 script.js \u0631\u0627 \u0645\u06cc\u200c\u062a\u0648\u0627\u0646\u06cc\u062f \u062a\u063a\u06cc\u06cc\u0631 \u062f\u0647\u06cc\u062f.<\/li>\n<li>\u06cc\u06a9 \u0639\u062f\u062f \u0631\u0627 \u0628\u06af\u06cc\u0631\u062f \u0648 \u0686\u06a9 \u06a9\u0646\u062f\u060c \u0622\u0646 \u0645\u06cc\u200c\u062a\u0648\u0627\u0646\u062f \u06cc\u06a9 \u06a9\u062f \u0645\u0644\u06cc \u0628\u0627\u0634\u062f \u06cc\u0627 \u0646\u0647.<\/li>\n<li><a href=\"https:\/\/behnudi.ir\/?p=957\" target=\"_blank\" rel=\"noopener\">\u0627\u0644\u06af\u0648\u0631\u06cc\u062a\u0645 \u062a\u0634\u062e\u06cc\u0635 \u062f\u0631\u0633\u062a\u06cc \u0634\u0645\u0627\u0631\u0647 \u0645\u0644\u06cc<\/a><\/li>\n<\/ul>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-848\" src=\"https:\/\/behnudi.ir\/f\/js1\/07\/img\/07-3.png\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0634\u0631\u0637 &#8211; Conditions \u062f\u0631 \u062c\u0627\u0648\u0627\u0633\u06a9\u0631\u06cc\u067e\u062a \u0634\u0631\u0637 \u0631\u0627 \u0628\u0647 \u0633\u0647 \u06af\u0648\u0646\u0647 \u0645\u06cc\u200c\u062a\u0648\u0627\u0646 \u0646\u0648\u0634\u062a. ? if Switch \u0647\u0645\u0647 \u0622\u0646\u0647\u0627 \u0631\u0627 \u0628\u0627\u06cc\u062f \u06cc\u0627\u062f \u06af\u0631\u0641\u062a \u0648 \u062f\u0631 \u0647\u0631 \u062c\u0627\u06cc\u06cc \u0622\u0646 \u0631\u0648\u0634\u06cc \u0631\u0627 \u06a9\u0647 \u0633\u0627\u062f\u0647\u200c\u062a\u0631 \u0627\u0633\u062a\u060c \u0628\u0647 \u06a9\u0627\u0631 \u0628\u0631\u062f. \u0633\u0648\u0626\u06cc\u0686 &#8211; Switch Switch \u062c\u0627\u06cc\u06af\u0632\u06cc\u0646 \u0686\u0646\u062f if \u0645\u06cc\u200c\u0634\u0648\u062f. if (exp === val1) { &#8230; } else if (exp === val2) { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1530,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20],"tags":[46,44],"class_list":["post-1568","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-computer-science","tag-javascript","tag-web-design"],"_links":{"self":[{"href":"https:\/\/behnudi.ir\/index.php?rest_route=\/wp\/v2\/posts\/1568","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/behnudi.ir\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/behnudi.ir\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/behnudi.ir\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/behnudi.ir\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1568"}],"version-history":[{"count":0,"href":"https:\/\/behnudi.ir\/index.php?rest_route=\/wp\/v2\/posts\/1568\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/behnudi.ir\/index.php?rest_route=\/wp\/v2\/media\/1530"}],"wp:attachment":[{"href":"https:\/\/behnudi.ir\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1568"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/behnudi.ir\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1568"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/behnudi.ir\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1568"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}