Romn numeral converter

help I tried so many times so many different variationsPreformatted text

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 if (number.value = 9) {
  result.textContent = "IX"
}
else if (number.value = 16) {
  result.textContent = "XVI"
}
else if (number.value = 649) {
  result.textContent = "DCXLIX"
}
else if (number.value = 1023) {
  result.textContent = "MXXIII"
}
else if (number.value = 3999) {
  result.textContent = "MMMCMXCIX"
};


function convertToRoman(num) {
let answer = "";
  let pairs = {
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(pairs);
    console.log(keys);
    while (num > 0) {
    let letter = "I"
    for (let i = 0; i < keys.length; i++) {
if (num >= pairs[keys[i]]) {
   letter = keys[i];
  break;
}
    }
    answer += letter;
   num = num - pairs[letter];
  }

  return answer;
}

One of your functions is not closed correctly.

Your output is not what is asked for. Do not add text in front of the value inside the element that should only have the value.


else if (number.value = 9) {
  result.textContent = "IX"
}
else if (number.value = 16) {
  result.textContent = "XVI"
}
else if (number.value = 649) {
  result.textContent = "DCXLIX"
}
else if (number.value = 1023) {
  result.textContent = "MXXIII"
}
else if (number.value = 3999) {
  result.textContent = "MMMCMXCIX"
};

Why are you hardcoding values? You do not need those if statements, your convertToRoman function is doing all the work.