Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
    Satchmo37
    @Satchmo37
    hint
    CamperBot
    @camperbot

    hint [8/8]

    Recursive Solution

    function repeat(str, num) {
      if(num < 0)
        return "";
      if(num === 1)
        return str;
      else
        return str + repeat(str, num - 1);
    }

    Credits:

    If you found this page useful, you can give thanks by copying and pasting this on the main chat: Thanks @Rafase282 @shadowfool

    NOTE: Please add your username only if you have added any relevant main contents to the wiki page. (Please don't remove any existing usernames.)

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Satchmo37
    @Satchmo37
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    Satchmo37
    @Satchmo37
    hint
    CamperBot
    @camperbot

    hint [1/8]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Satchmo37
    @Satchmo37
    hint
    CamperBot
    @camperbot

    hint [2/8]

    # Explanation:

    The program is very simple, we have to take a variable and return that variable being repeated certain amount of times. No need to add space or anything, just keep repeating it into one single string.

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Satchmo37
    @Satchmo37
    hint
    CamperBot
    @camperbot

    hint [3/8]

    Hint: 1

    You can't edit strings, you will need to create a variable to store the new string.

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Molly Eichar
    @terra-bites
    hint
    CamperBot
    @camperbot

    hint [1/8]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Molly Eichar
    @terra-bites
    hint
    CamperBot
    @camperbot

    hint [2/8]

    # Explanation:

    The program is very simple, we have to take a variable and return that variable being repeated certain amount of times. No need to add space or anything, just keep repeating it into one single string.

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Molly Eichar
    @terra-bites
    hint
    CamperBot
    @camperbot

    hint [3/8]

    Hint: 1

    You can't edit strings, you will need to create a variable to store the new string.

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Omar
    @Ohmarr
    hint
    CamperBot
    @camperbot

    hint [1/8]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Omar
    @Ohmarr
    hint
    CamperBot
    @camperbot

    hint [2/8]

    # Explanation:

    The program is very simple, we have to take a variable and return that variable being repeated certain amount of times. No need to add space or anything, just keep repeating it into one single string.

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Omar
    @Ohmarr
    hint
    CamperBot
    @camperbot

    hint [3/8]

    Hint: 1

    You can't edit strings, you will need to create a variable to store the new string.

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Omar
    @Ohmarr
    hint
    CamperBot
    @camperbot

    hint [4/8]

    Hint: 2

    Create a loop to repeat the code as many times as needed.

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Omar
    @Ohmarr
    hint
    CamperBot
    @camperbot

    hint [5/8]

    Hint: 3

    Make the variable created store the current value and append the word to it.

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Omar
    @Ohmarr
    hint
    CamperBot
    @camperbot

    hint [6/8]

    Spoiler Alert!

    687474703a2f2f7777772e796f75726472756d2e636f6d2f796f75726472756d2f696d616765732f323030372f31302f31302f7265645f7761726e696e675f7369676e5f322e676966.gif

    Solution ahead!

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Omar
    @Ohmarr
    hint
    CamperBot
    @camperbot

    hint [7/8]

    Code Solution:

    function repeat(str, num) {
      var accumulatedStr = '';
    
      while (num > 0) {
        accumulatedStr += str;
        num--;
      }
    
      return accumulatedStr;
    }

    Second Solution:

    function repeat(str, num) {
      var newstr = [];
      for (var i = 0; i < num; i++) {
        newstr.push(str);
      }
      return newstr.join('');
    }
    
    repeat("abc", 3);

    Code Explanation:

    • Create a variable to store the repeated word.
    • Use a while loop or for loop to repeat code as many times as needed according to num
    • The we just have to add the string to the variable created on step one. and increase or decrease num depending on how you set the loop.
    • At the end of the loop, return the variable for the repeated word.

    Third Solution:

    function repeat(str, num) {
      if (num < 0) {
        return "";
      } 
      else {
        return str.repeat(num);
      }
    }
    
    repeat("abc", 3);

    Code Explanation:

    • First check if num is a negative number and return false if so
    • as of ECMA Script 6 (ES6) the String object comes with a builtin function to repeat a string which we you can use

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Yasna
    @Ansaii
    hint
    CamperBot
    @camperbot

    hint [1/8]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Yasna
    @Ansaii
    hint
    CamperBot
    @camperbot

    hint [2/8]

    # Explanation:

    The program is very simple, we have to take a variable and return that variable being repeated certain amount of times. No need to add space or anything, just keep repeating it into one single string.

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Yasna
    @Ansaii
    hint
    CamperBot
    @camperbot

    hint [3/8]

    Hint: 1

    You can't edit strings, you will need to create a variable to store the new string.

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Yasna
    @Ansaii
    hint
    CamperBot
    @camperbot

    hint [4/8]

    Hint: 2

    Create a loop to repeat the code as many times as needed.

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Yasna
    @Ansaii
    hint
    CamperBot
    @camperbot

    hint [5/8]

    Hint: 3

    Make the variable created store the current value and append the word to it.

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Yasna
    @Ansaii
    hint
    CamperBot
    @camperbot

    hint [6/8]

    Spoiler Alert!

    687474703a2f2f7777772e796f75726472756d2e636f6d2f796f75726472756d2f696d616765732f323030372f31302f31302f7265645f7761726e696e675f7369676e5f322e676966.gif

    Solution ahead!

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Yasna
    @Ansaii
    hint
    CamperBot
    @camperbot

    hint [7/8]

    Code Solution:

    function repeat(str, num) {
      var accumulatedStr = '';
    
      while (num > 0) {
        accumulatedStr += str;
        num--;
      }
    
      return accumulatedStr;
    }

    Second Solution:

    function repeat(str, num) {
      var newstr = [];
      for (var i = 0; i < num; i++) {
        newstr.push(str);
      }
      return newstr.join('');
    }
    
    repeat("abc", 3);

    Code Explanation:

    • Create a variable to store the repeated word.
    • Use a while loop or for loop to repeat code as many times as needed according to num
    • The we just have to add the string to the variable created on step one. and increase or decrease num depending on how you set the loop.
    • At the end of the loop, return the variable for the repeated word.

    Third Solution:

    function repeat(str, num) {
      if (num < 0) {
        return "";
      } 
      else {
        return str.repeat(num);
      }
    }
    
    repeat("abc", 3);

    Code Explanation:

    • First check if num is a negative number and return false if so
    • as of ECMA Script 6 (ES6) the String object comes with a builtin function to repeat a string which we you can use

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Yasna
    @Ansaii
    hint
    CamperBot
    @camperbot

    hint [8/8]

    Recursive Solution

    function repeat(str, num) {
      if(num < 0)
        return "";
      if(num === 1)
        return str;
      else
        return str + repeat(str, num - 1);
    }

    Credits:

    If you found this page useful, you can give thanks by copying and pasting this on the main chat: Thanks @Rafase282 @shadowfool

    NOTE: Please add your username only if you have added any relevant main contents to the wiki page. (Please don't remove any existing usernames.)

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Jorge
    @liberaltech
    Hint
    CamperBot
    @camperbot

    hint [1/1]

    ## :construction: After this are possible spoiler hints.

    Make sure you've tried to hard to solve it yourself before proceeding. :construction:

    type hint for next hint :pencil: [Contribute at the FCC Wiki]

    Jorge
    @liberaltech
    Hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page