Tell us what’s happening:
I’m done with all the script and html code and i’ve linked the script to the html body element but for some reason it’s not accepting the code can someone check if i linked it properly or the problem lies somewhere else. Please any hint will be much appreciated
Your code so far
<!-- 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 */
/* file: script.js */
document.getElementById('convert-btn').addEventListener('click', () => {
const inputNumber = parseInt(document.getElementById('number').value)
if (isNaN(inputNumber) || inputNumber < 1) {
document.getElementById('ouput').textContent = "Please enter a valid number"
} else if (inputNumber < 1) {
document.getElementById('ouput').textContent = "Please enter a number greater than or equal to 1"
} else if (inputNumber >= 4000) {
document.getElementById('ouput').textContent = "Please enter a number less than or equal to 3999"
} else {
const romanNumerals = convertToRoman(inputNumber);
document.getElementById('output').textContent = romanNumerals;
}
});
function convertToRoman (num) {
const romanNumeral = '';
const romanNumeralMapping = [
{ 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' }
];
for(let i=0; i < romanNumeralMapping.length; i++) {
while (num >= romanNumeralMapping[i].value) {
romanNumeral += romanNumeralMapping[i].numeral;
num -= romanNumeralMapping[i].value;
}
}
return romanNumeral;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Challenge Information:
Build a Roman Numeral Converter Project - Build a Roman Numeral Converter