squares

    0

    0

    The function squares takes two arguments, a and b. It will first create a variable called count and set it to 0. It will then keep track of how many times the function has been called by counting from 1 up to but not including the value of b. If the value of i is equal to the value of b, then the function will return immediately. If the value of i is greater than the value of b, then the function will add 1 to i and continue counting from 1 up to but not including the value of b. When the value of i reaches the value of b, the function will return the value of count.

    function squares(a, b) {
      let count = 0;
      let i = 1;
      while (i * i <= b) {
        if (i * i >= a) {
          count++;
        }
        i++;
      }
      return count;
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.