Build a Roman Numeral Converter Project - Build a Roman Numeral Converter

Tell us what’s happening:

My code isn’t even returning a result in the console. I don’t know if I’m referring to the wrong variables or what. Could someone give me a hand with this?

Your code so far

<!-- file: index.html -->
<html>
  <head>
    <meta charset="utf-8" />
    <link rel="stylesheet" href="styles.css" />
    <link rel="scriptsheet" href="./script.js" />
<title>Roman Numeral Converter</title>
  </head>
  <body>
<label for="number">Enter Numbers: </label>
<input id="number"></input>
<button id="convert-btn">convert</button>
<div id="output"></div>
<script src="./script.js"></script>
  </body>
</html>
<link rel="scriptsheet" href="./script.js" />
/* file: styles.css */

/* file: script.js */
const number = document.getElementById("number");
const convertBtn = document.getElementById("convert-btn");
const output = document.getElementById("output");

const checkIfNumber = () => {
  if (number.length >=  1){
    output.textContent = "Please enter a valid number";
  } else if (number.value < 0){
    output.textContent = "Please enter a number greater than or equal to 1";
  } else if(number.value > 3999){
    output.textContent = "Please enter a number less than or equal to 3999";
  }
}

/*function convertToRoman(num){

 if (checkIfNumber() === 0){

 const romanNumeral ="";

 const roman = {   
   numerals: [{
   value: 1000, numeral: "M"},
   {value: 900, numeral:"CM"},
   {value: 500, numeral: "D"},
   {value: 400, numeral: "CD"},
   {value: 100, numeral:"C"},
   {value: 90, numeral:"XC"},
   {value: 50, numeral:"L"},
   {value: 40, numeral:"XL"},
   {value: 10, numeral:"X"},
   {value: 9, numeral: "IX"},
   {value: 5, numeral: "V"},
   {value: 4, numeral: "IV"},
   {value: 3, numeral: "III"},
   {value: 2, numeral: "II"},
   {value: 1, numeral: "I"}],
   values: [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 3, 2 ,1]
 };
 for (let i = 0; 
 i < roman.length; i++){while (num >= roman[i].value) {romanNumeral += roman[i].numeral; 
 num -= roman[i].value
 }
  return romanNumeral;
  console.log(romanNumeral);
 }
}
}*/
function integer_to_roman(num) {
if (checkIfNumber() !== 1){return} 
else{ 

var digits = String(+num).split(""),
key = ["","C","CC","CCC","CD","D","DC","DCC","DCCC","CM",
"","X","XX","XXX","XL","L","LX","LXX","LXXX","XC",
"","I","II","III","IV","V","VI","VII","VIII","IX"],
roman_num = "",
i = 3;
while (i--)
roman_num = (key[+digits.pop() + (i * 10)] || "") + roman_num;
return Array(+digits.join("") + 1).join("M") + roman_num;
}
}
const converting = () => {
integer_to_roman(number)
console.log(integer_to_roman(number))};
convertBtn.addEventListener("click", integer_to_roman);

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.4 Safari/605.1.15

Challenge Information:

Build a Roman Numeral Converter Project - Build a Roman Numeral Converter

If you are referring to the console.log call in the converting function, I don’t see where your code is calling that function? I’m not sure what the purpose of the converting function is? Can you explain?

remove this please 

My thought process was that I had to specify what the integer_to_roman function was being called on. So I wrote another function that called that function on the number variable.

The integer_to_roman function is being called whenever you click the button:

convertBtn.addEventListener("click", integer_to_roman);

That’s all you need. Nothing else needs to call the integer_to_roman function. So you can get rid of the converting function completely.

Now you need to figure out why you aren’t getting the correct results for all of the tests. I’d start with fixing the checkIfNumber function and making sure all of those checks are correct.