Tell us what’s happening:
I wrote my program on my local machine and it works fine. I put it online and run the test but the points 5, 6, 12 and 13 didn’t pass. point 4 did pass well. I checked for typos, changed greater than in greater than or equal to or visa-versa, stript all my comments and all the code that I add to make it a little nicer but I can’t find why my code doesn’t pass.
Your code so far
<!-- file: index.html -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Roman Numeral Converter</title>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<div id="container">
<img src="https://www.boermastreek.nl/han/freecodecamp/photos/hansConverter.png" alt="Hans converter logo" />
<h1>Roman numeral converter</h1>
<form id="form">
<h2>Add your number to convert</h2>
<input id="number" type="number" placeholder="Type here your number"></input>
</form>
<button id="convert-btn">Convert</button>
<div id="output"></div><br>
</div>
<script src="script.js"></script>
</body>
</html>
/* file: styles.css */
body {
background-color: black;
}
#container {
display:flex;
flex-direction: column;
width: 500px;
align-items: center;
background-color: yellow;
margin: 20px auto;
}
#form {
border: 5px solid black;
}
h2 {
text-align: center;
}
#number{
width: 400px;
height: 30px;
margin: 20px;
font-size: 20px;
text-align: center;
background-color: black;
color: white;
}
::placeholder {
color: yellow;
}
#convert-btn {
width: 400px;
height: 30px;
margin: 20px;
font-size: 20px;
background-color: black;
color: yellow;
}
#output {
width: 400px;
height: 40px;
margin: 10px 20px;
font-size: 30px;
text-align: center;
}
/*Media*/
@media screen and (max-width: 800px){
#container {
width: 500px;
margin:auto;
}
body {
background-color: yellow;
min-width: 500px;
}
}
/* file: script.js */
const number = document.getElementById("number");
const convertBtn = document.getElementById("convert-btn");
const output = document.getElementById("output");
convertBtn.addEventListener("click", () => {
if (!number.value) {
output.innerText = "Please enter a valid number";
return;
}
if (number.value < 1) {
output.innerText = "Please enter a number greater then or equal to 1";
return;
}
if (number.value >= 4000) {
output.innerText = "Please enter a number less then or equal to 3999";
return;
}
const outputConvertedRomanNumber = convertInputToRomanNumber(number.value);
output.innerText = outputConvertedRomanNumber;
})
const convertInputToRomanNumber = (numberToConvert) => {
const romanNumerals = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"];
const arabicNumerals = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
let romanNumber = "";
let indexNumber = 0;
while (numberToConvert > 0) {
const numberOfSymbols = Math.floor(numberToConvert / arabicNumerals[indexNumber]);
numberToConvert -= numberOfSymbols * arabicNumerals[indexNumber];
romanNumber += romanNumerals[indexNumber].repeat(numberOfSymbols);
indexNumber++;
};
return romanNumber;
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0
Challenge Information:
Build a Roman Numeral Converter Project - Build a Roman Numeral Converter