• <i id='2ItD7'><tr id='2ItD7'><dt id='2ItD7'><q id='2ItD7'><span id='2ItD7'><b id='2ItD7'><form id='2ItD7'><ins id='2ItD7'></ins><ul id='2ItD7'></ul><sub id='2ItD7'></sub></form><legend id='2ItD7'></legend><bdo id='2ItD7'><pre id='2ItD7'><center id='2ItD7'></center></pre></bdo></b><th id='2ItD7'></th></span></q></dt></tr></i><div id='2ItD7'><tfoot id='2ItD7'></tfoot><dl id='2ItD7'><fieldset id='2ItD7'></fieldset></dl></div>

        <bdo id='2ItD7'></bdo><ul id='2ItD7'></ul>

    1. <small id='2ItD7'></small><noframes id='2ItD7'>

    2. <legend id='2ItD7'><style id='2ItD7'><dir id='2ItD7'><q id='2ItD7'></q></dir></style></legend>
        <tfoot id='2ItD7'></tfoot>

        JavaScript函数没有将我的参数传递给其他函数

        JavaScript function not passing my parameters to other function(JavaScript函数没有将我的参数传递给其他函数)

      1. <tfoot id='MjA8y'></tfoot>

              <i id='MjA8y'><tr id='MjA8y'><dt id='MjA8y'><q id='MjA8y'><span id='MjA8y'><b id='MjA8y'><form id='MjA8y'><ins id='MjA8y'></ins><ul id='MjA8y'></ul><sub id='MjA8y'></sub></form><legend id='MjA8y'></legend><bdo id='MjA8y'><pre id='MjA8y'><center id='MjA8y'></center></pre></bdo></b><th id='MjA8y'></th></span></q></dt></tr></i><div id='MjA8y'><tfoot id='MjA8y'></tfoot><dl id='MjA8y'><fieldset id='MjA8y'></fieldset></dl></div>
              <legend id='MjA8y'><style id='MjA8y'><dir id='MjA8y'><q id='MjA8y'></q></dir></style></legend>

              <small id='MjA8y'></small><noframes id='MjA8y'>

              • <bdo id='MjA8y'></bdo><ul id='MjA8y'></ul>

                  <tbody id='MjA8y'></tbody>
                • 本文介绍了JavaScript函数没有将我的参数传递给其他函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我遇到了一个问题,我试图将参数从一个函数发送到另一个函数,接收参数的函数使用 switch 语句对其进行评估并返回它,但它只返回我放入其中的任何变量例如,而不是高级大师".这是我不明白我做错了什么的代码,请记住我对编码很陌生,也许有人可以给我一些指示.提前致谢.

                  I'm having a problem where I'm trying to send parameters from one function to another, the function that receives the parameters uses a switch statement to evaluate it and returns it but it just returns what ever variable I put into it instead of "senior Master" for example. Here is the code I don't get what I'm doing wrong, just keep in mind I'm very new to coding maybe someone can give me some pointers. Thanks in advance.

                  function calculatexxx(x)  {
                      let calculatexxx= x;
                      switch (x) {
                          case (x >= 2400):
                              console.log("Senior Master");
                              break;
                          case (2399 > x > 2200):
                              console.log("National Master");
                              break;
                          case (2199 > x> 2000):
                              console.log("Expert");
                              break;
                          case (1999 > x> 1800):
                              console.log("Class A");
                              break;
                          case (1799 > x> 1600):
                              console.log("Class B");
                              break;
                          default:
                              console.log("Error input not valid");
                  
                      return(x);
                  
                      }
                  }
                  function displayxxx() {
                      console.log("Your Rank is: " + calculatexxx(2400)); // 
                  
                  }
                  displayxxx(); 
                  

                  推荐答案

                  看看这个表达式就行了

                  2399 > x > 2200
                  

                  并取三个值,例如零、2300(这应该返回 true)和 10000.

                  and take three values, like zero, 2300 (this should return true) and 10000.

                  表达式按出现顺序执行,因为是同一个操作符.

                  The expression is executed in order of appearance, because of the same operator.

                        x     2399 > x     value   value > 2200     yield     result
                  --------  ------------  -------  ------------  ----------  --------
                        0   2399 >     0    true    true > 2200   1 > 2200     false
                     2300   2399 >  2300    true    true > 2200   1 > 2200     false
                   100000   2399 > 10000   false   false > 2200   0 > 2200     false
                  

                  最终结果总是false,因为第一部分返回一个布尔值,并且转换后的值永远不会大于最后一个值.

                  The final result is always false, because the first part returns a boolean value and the converted value is never greater than the last value.

                  结论

                  进行两个与 相关的比较逻辑与 &&:

                  Take two comparisons connected with logical AND &&:

                  2399 > x && x > 2200
                  


                  对于一个 switch 语句,您需要在条件部分和其他条件的情况下获取比较值.而直接返回,你可以省略break,因为函数以它结束.


                  For taking a switch statement, you need to take the comparison value in the condition part and in the cases the other condition. And by returning directly, you could omit break, because the function ends with it.

                  function calculate(x) {
                      switch (true) {
                          case x >= 2400: return "Senior Master";
                          case x >= 2200: return "National Master";
                          case x >= 2000: return "Expert";
                          case x >= 1800: return "Class A";
                          case x >= 1600: return "Class B";
                      }
                      return "Error input not valid";
                  }
                  
                  function display() {
                      console.log("Your Rank is: " + calculate(2400));
                  }
                  
                  display();

                  另一种解决方案可能是使用连续的 if 语句并提前返回.这种方法更好,因为它不会误用 select 的原始思想,即必须比较两个值.

                  Another solution could be to use continuing if statements and return early. This approach is better, because it does not missuse the original idea of select where two values have to be compared.

                  function calculate(x) {
                      if (x >= 2400) return "Senior Master";
                      if (x >= 2200) return "National Master";
                      if (x >= 2000) return "Expert";
                      if (x >= 1800) return "Class A";
                      if (x >= 1600) return "Class B";
                      return "Error input not valid";
                  }
                  
                  function display() {
                      console.log("Your Rank is: " + calculate(2400));
                  }
                  
                  display();

                  这篇关于JavaScript函数没有将我的参数传递给其他函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Pause youtube video, youtube api(暂停 youtube 视频,youtube api)
                  Youtube iframe api not triggering onYouTubeIframeAPIReady(Youtube iframe api 未触发 onYouTubeIframeAPIReady)
                  How can I stop a video with Javascript in Youtube?(如何在 Youtube 中停止使用 Javascript 的视频?)
                  How to call Greasemonkey#39;s GM_ functions from code that must run in the target page scope?(如何从必须在目标页面范围内运行的代码中调用 Greasemonkey 的 GM_ 函数?)
                  How do you mute an embedded Youtube player?(如何使嵌入式 Youtube 播放器静音?)
                  How to get number of video views with YouTube API?(如何使用 YouTube API 获取视频观看次数?)
                    <tfoot id='nKDWv'></tfoot>
                    <legend id='nKDWv'><style id='nKDWv'><dir id='nKDWv'><q id='nKDWv'></q></dir></style></legend>
                  1. <small id='nKDWv'></small><noframes id='nKDWv'>

                      • <bdo id='nKDWv'></bdo><ul id='nKDWv'></ul>
                      • <i id='nKDWv'><tr id='nKDWv'><dt id='nKDWv'><q id='nKDWv'><span id='nKDWv'><b id='nKDWv'><form id='nKDWv'><ins id='nKDWv'></ins><ul id='nKDWv'></ul><sub id='nKDWv'></sub></form><legend id='nKDWv'></legend><bdo id='nKDWv'><pre id='nKDWv'><center id='nKDWv'></center></pre></bdo></b><th id='nKDWv'></th></span></q></dt></tr></i><div id='nKDWv'><tfoot id='nKDWv'></tfoot><dl id='nKDWv'><fieldset id='nKDWv'></fieldset></dl></div>
                          <tbody id='nKDWv'></tbody>