Tell us what’s happening:
What is wrong?This JAVA code should fill all conditions:
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<script rel="stylesheet" src="script.js">
</script>
<head>
<meta name=viewport
content="width=device-width, initialscale=1.0">
<meta charset=UTF-8>
<meta name="viewport" content="width=device-width, intial-scale=1.0">
</head>
<input id=number type=text ></input>
<button id="convert-btn">
CONVERT
</button>
<p id=output><p>
</html>
/* file: styles.css */
.output{color:red;
width:90%;
max-width:499px;
min-width:54px;
margin-top:25px;
padding:15px;
border:3px var(--gray-05);
text-align:center;
overflow-wrap:break-word;
}
/* file: script.js */
const convertNumerals=(num)=>{
const ref=[{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:1,numeral:"I"}];
if (num<1){
output.textContent="Please enter a number greater than or equal to 1";return}
if (num >=4000){ output.textContent="Please enter a number less than or equal to 3999";return}
let roman="";
for(let i=0;i<ref.length;i++){while
(num >=ref[i].value){roman+=ref[i].numeral;num -=ref[i].value} };
}
const numberInput=document.getElementById("number");
const convertBtn=document.getElementById("convert-btn");
const output=document.getElementById("output");
document.addEventListener("DOMContentLoader",()=>{const convertBtn =document.getElementById("convert-btn");
if(convertBtn)
{ const num=parseInt(numberInput.value,10);
if(isNaN(num)){output.textContent="Please enter a valid number"
return
}
output.textContent=convertNumerals(num);
}
else{console.error("Element with id'convert-btn' not found")}
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36 Edg/135.0.0.0
Challenge Information:
Build a Roman Numeral Converter Project - Build a Roman Numeral Converter