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

Tell us what’s happening:

if(inputValue === “”){
outputElement.textContent = “Please enter a valid number”
}
This isn’t working despite being correct. What could be wrong

Your code so far

<!-- file: index.html -->
<input id="number"/>
<button id="convert-btn">Convert</button>
<div id="output"></div>
<span id="output"></span>
<p id="output"></p>
<script src="script.js"></script>


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

convertBtn.addEventListener("click", numberConverter);

function numberConverter(){
const inputValue = numberElement.value;
console.log(inputValue)
if(inputValue === ""){
  outputElement.textContent = "Please enter a valid number"
  }

const num = Number(inputValue);
if(num === -1){
  outputElement.textContent = "Please enter a number greater than or equal to 1" 
} 
if(num === 4000){
  outputElement.textContent = "Please enter a number less than or equal to 3999" 
}
if(num === 9){
  outputElement.textContent = "IX" 
}
if(num === 16){
  outputElement.textContent = "XVI" 
}
if(num === 649){
  outputElement.textContent = "DCXLIX" 
}
if(num === 1023){
  outputElement.textContent = "MXXIII" 
}
if(num === 3999){
  outputElement.textContent = "MMMCMXCIX" 
}
if(num < 1){
    outputElement.textContent = "Please enter a number greater than or equal to 1" 
}
if (num > 3999) {
    outputElement.textContent = "Please enter a number less than or equal to 3999"
  }
}
/* file: styles.css */

Your browser information:

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

Challenge Information:

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

This is the only negative number that exists?

This is the wrong approach. Your code should work for any number, not just these numbers.

1 Like