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

Tell us what’s happening:

I have tested a lot changed things added nothing works, what am I not seeing ?

Your code so far

<!-- file: index.html -->
<!-- file: index.html -->
<!DOCTYPE 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>
/* file: styles.css */
:root {
  --gray-00: #ffffff;
  --gray-05: #f5f6f7;
  --gray-15: #d0d0d5;
  --gray-75: #3b3b4f;
  --gray-85: #1b1b32;
  --gray-90: #0a0a23;
  --blue-50: #198eee;
  --error: #a94442;
  --danger-color: #850000;
  --danger-background: #ffadad;
}

*,
::before,
::after {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
}

body {
  min-height: 100vh;
  padding: 50px 20px;
  font-family: 'Lato', Helvetica, Arial, sans-serif;
  font-size: 18px;
  background-color: var(--gray-85);
  color: var(--gray-05);
}

main {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.freecodecamp-logo {
  height: 30px;
  margin-bottom: 20px;
}

h1 {
  text-align: center;
  margin: 20px auto;
  max-width: 350px;
  font-family: 'Castoro Titling', cursive;
}

form {
  color: var(--gray-05);
  margin: auto 25px;
  padding: 15px auto;
  border: 3px solid var(--gray-05);
  text-align: center;
  width: 90%;
  max-width: 500px;
  background-color: var(--gray-75);
}

fieldset {
  border: 0 none;
  height: 100%;
  padding: 25px;
  margin: 10px 20px;
}

label {
  display: inline-block;
  font-size: 1.5rem;
  margin-bottom: 10px;
  font-weight: bold;
}

input:focus-visible,
button:focus-visible {
  outline: 3px solid var(--blue-50);
}

input {
  display: block;
  font-size: 2.5rem;
  width: 100%;
  height: 60px;
  padding: 6px 12px;
  margin: 10px 0;
  line-height: 1.4;
  color: white;
  background-color: var(--gray-90);
  border: 1px solid var(--gray-05);
}

button {
  cursor: pointer;
  margin-top: 15px;
  text-decoration: none;
  background-image: linear-gradient(#fecc4c, #ffac33);
  border: 3px solid #feac32;
  padding: 10px 16px;
  font-size: 23px;
  width: 100%;
}

.output {
  color: white;
  background-color: var(--gray-75);
  border: 3px solid var(--gray-05);
  font-size: 2.5rem;
  width: 90%;
  max-width: 500px;
  min-height: 55px;
  margin-top: 25px;
  padding: 15px;
  overflow-wrap: break-word;
  text-align: center;
}

.alert {
  font-size: 2rem;
  background-color: var(--danger-background);
  border: 3px solid var(--danger-color);
  color: var(--danger-color);
}

.hidden {
  display: none;
}
/* file: script.js */
let number = document.getElementById("number");
let btn = document.getElementById("convert-btn");
let result = document.getElementById("output");

btn.addEventListener("click", numberInput);
function numberInput(){
  
if(number.value === ''){
  result.textContent="Please enter a valid number";
}
else if (number.value < 1){
  result.textContent="Please enter a number greater than or equal to 1";
}
else if (number.value >=4000){
  result.textContent="Please enter a number less than or equal to 3999";
}
 else if (number.value < 4000) {
   result.textContent = "Roman Numeral:" + convertToRoman(number.value);
 
} else {
  return true;
}

function convertToRoman(num) {
let romanNumeral = '';
  let romanList = [
['M', 1000],
['CM', 900],
['D',	500],
['CD', 400],
['C',	100],
['XC',	90],
['L',	50],
['XL',	40],
['X',	10],
['IX',	9],
['V',	5],
['IV',	4],
['I',	1],
  ]

   let keys = Object.keys(romanList);
    console.log(keys);
    while (num > 0) {
    let letter = "I"
    for (let i = 0; i < keys.length; i++) {
if (num >= romanList[keys[i]]) {
   letter = keys[i];
  break;
}
    }
    romanNumeral += letter;
   num = num - romanList[letter];
  }

  return answer;

}
}

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/121.0.0.0 Safari/537.36 OPR/107.0.0.0

Challenge Information:

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

can you explain what does it mean that nothing works? I have no idea where to start looking for issues if you don’t give some details

Hi @ElCelo27

answer is not defined.

This is the variable you want to return?

Also I don’t think the following is valid code:

You already have the script element in the correct spot.

Happy coding

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.