Build a Roman Numeral Convertor - Javascript Alghoritms and Data Structures (Beta)

please can you tell me whats wrong with my code?
its working but not doing anything…
link: https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/build-a-roman-numeral-converter-project/build-a-roman-numeral-converter
//HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <link rel="stylesheet" href="styles.css">
    <title>Roman Numeral Converter</title>
    </head>
    <body>
      <h1>ROMAN NUMBERAL CONVERTER</h1>
      <p>This site provides in transforming a numeral into a roman number.</p>
      <input id="number"/>
      <button id="convert-btn">Convert</button>
      <div id="output">
        </div>
    <script src="script.js"></script>
        </body>

          </html>

CSS

h1{
 font-family: 'sans-serif', Arial;
 color: #1ea2b1;
 background-color: black;
 margin: 0 0 0 0;
 padding: 1px 2px 1px 2px;
 text-align: center;
}
p{
  font-family: 'sans-serif', Helvetica;
  color:#1ea2b1;
  background-color: black;
}
button{
  font-family: 'sans-serif', Helvetica;
}
body{
  background-color:black;
}
input{
  position: center;
  margin: 2px 4px 2px 4px;
  padding: 0 0 0 0;
  background-color: lightblue;
  
}

JS

const number=document.getElementById("number");
const convert=document.getElementById("convert-btn");
const output=document.getElementById("output");
const numeral=[
  ["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]
]
input.addEventListener("keydown",  e =>{
if(e.key="Enter"){
  convert.click();
}
})

convert.addEventListener("click", ()=>{
  let result="";
  let value = input.value;
  if(!value){output.innerText="Please enter a valid number"} else if(value<0){ output.innerText="Please enter a number greater than or equal to 1"} else if(value>3999){ output.innerText="Please enter a number less than or equal to 3999"}else{
    let result="";
    for(const [roman,number] of numeral){
      while(number<value){
        result+=number;
        value -= number;
      }
    }
    output.innerText=result;
  }
})

Hi there!

Also Add a link to the challenge project.

1 Like

sorry, i added it now
first time here :smiley:

This is a very cryptic statement? How can your code be working and yet, not doing anything? Perhaps provide more details?

First you have to double check whether the value entered by the user is correctly obtained.

I’ve figured it out, thanks :slight_smile: