Where communities thrive


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

    hint [2/6]

    # Problem Explanation:

    • You will create a program that converts an integer to a roman numeral.

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

    Ragnar Örn Ólafsson
    @ragnaro89
    bonfire Find the Longest Word in a String
    CamperBot
    @camperbot

    :fire:Bonfire: Find the Longest Word in a String :link:

    function findLongestWord(str) {
      return str.length;
    }
    
    findLongestWord('The quick brown fox jumped over the lazy dog');

    Return the length of the longest word in the provided sentence.

    more info:  bf details | bf links | hint

    Ragnar Örn Ólafsson
    @ragnaro89
    hint
    CamperBot
    @camperbot

    hint [3/6]

    Hint: 1

    • Creating an array with the Roman Numerals and one with the decimal equivalent for the new forms will be very helpful.

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

    Ragnar Örn Ólafsson
    @ragnaro89
    hint Find the Longest Word in a String
    CamperBot
    @camperbot

    hint [4/6]

    Hint: 2

    • If you add the numbers that go before the new letter is introduced, it will save you plenty of code, like values for 4, 9, and 40.

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

    Ragnar Örn Ólafsson
    @ragnaro89
    hint
    CamperBot
    @camperbot

    hint [5/6]

    Hint: 3

    • You can't have more than three consecutive Roman numerals together.

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

    Ragnar Örn Ólafsson
    @ragnaro89
    hint
    CamperBot
    @camperbot

    hint [6/6]

    Spoiler Alert!

    687474703a2f2f7777772e796f75726472756d2e636f6d2f796f75726472756d2f696d616765732f323030372f31302f31302f7265645f7761726e696e675f7369676e5f322e676966.gif

    Solution ahead!

    Code Solution:

    var convert = function(num) {
    
      // Create arrays with default conversion with matching indices.
      var decimalValue = [ 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 ];
      var romanNumeral = [ 'M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I' ];
    
      //empty string variable for the final roman number
    
      var romanized = '';
    
      // Loop through the indices of the decimalValue array.
      for (var index = 0; index < decimalValue.length; index++) {
        // Continue to loop while the value at the current index will fit into numCopy
        while (decimalValue[index] <= num) {
          // Add the Roman numeral & decrease numCopy by the decimal equivalent.
          romanized += romanNumeral[index];
          num -= decimalValue[index];
        }
      }
    
      return romanized;
    };

    Code Explanation:

    • Read comments on code.

    Credits:

    If you found this page useful, you can give thanks by copying and pasting this on the main chat: Thanks @Rafase282 @SaintPeter @benschac for your help with Bonfire: Roman Numeral Converter

    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]

    showhuo
    @showhuo
    Manage Packages with NPM
    Ghost
    @ghost~56a80c91e610378809be5d28
    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]

    Ghost
    @ghost~56a80c91e610378809be5d28
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    Ghost
    @ghost~56a80c91e610378809be5d28
    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]

    Jason Watkins
    @jasonwatkins
    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]

    Jason Watkins
    @jasonwatkins
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    Jason Watkins
    @jasonwatkins
    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]

    wonsi
    @wonsi
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    momobgood
    @momobgood
    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]

    momobgood
    @momobgood
    hint
    CamperBot
    @camperbot
    These hints depend on people like you! Please add to this :point_right: Bonfire's Wiki Hints Page
    Chao Deng
    @autumnm1981
    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]

    Deepak Chirammel
    @DeepakChirammel
    Spoiler Alert !!!!
    function convertToRoman(num) {
    
      var roman = {"1": "I", "2": "II", "3": "III", "4": "IV", "5": "V", "6": "VI", "7": "VII", "8": "VIII", "9": "IX", "10": "X", "20": "XX", "30": "XXX", "40": "XL", "50": "L", "60": "LX", "70": "LXX", "80": "LXXX", "90": "XC", "100": "C", "200": "CC", "300": "CCC", "400": "CD", "500": "D", "600": "DC", "700": "DCC", "800": "DCCC", "900": "CM", "1000": "M", "2000": "MM", "3000": "MMM"};
    
      return num.toString().split("").map(function(val, index, n) {
        return roman[(val * (Math.pow(10, n.length - index - 1))).toString()];
      }).join("");
    }
    Ahmad Kampoori
    @akampoori
    @Deepak Chairman that what I am looking for code like yours. Need some advice and help in numeral-roman converter challenge. I I have already solved the challenge but I need to use of splice , indexOf and join methods. Also need to avoid nested loop. I know you can use higher order functions to avoid the loop. Or functional method. Thank you for your help.
    CamperBot
    @camperbot
    :cookie: 61 | @deepak |http://www.freecodecamp.com/deepak
    akampoori sends brownie points to @deepak :sparkles: :thumbsup: :sparkles: