hint [6/6]
Solution ahead!
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;
};
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]
:star: 2238 | @saintpeter | http://www.freecodecamp.com/saintpeter
:star: 839 | @rafase282 | http://www.freecodecamp.com/rafase282
:star: 317 | @benschac | http://www.freecodecamp.com/benschac
Hi, I'm CamperBot! I can help you in this chatroom :smile:
find TOPIC
find all entries about topic. ex: find js
wiki TOPIC
show contents of topic pagethanks @username
send brownie points to another userabout @username
shows info on that userbonfire BONFIRENAME
info on a bonfire:speech_balloon: meet CamperBot in this room!
hint [1/6]
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]
hint [2/6]
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
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
hint [3/6]
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [4/6]
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [5/6]
type
hint
for next hint :pencil: [Contribute at the FCC Wiki]
hint [6/6]
Solution ahead!
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;
};
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]
hint [1/1]
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]
hint [1/1]
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]
hint [1/1]
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]
hint [1/1]
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]
hint [1/1]
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]
hint [1/1]
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]
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("");
}
akampoori sends brownie points to @deepak :sparkles: :thumbsup: :sparkles: