How to Create CONVERT DECIMAL NUMBER INTO ROMAN NUMBER in HTML

 

How to Create CONVERT DECIMAL NUMBER INTO ROMAN NUMBER in HTML





This tutorial will guide you through creating a CONVERT DECIMAL NUMBER INTO ROMAN NUMBER using HTML, CSS & JavaScript. Follow all the given step :

Step 1 : Create Index.html and add given html code on it.
Step 2 : Create style.css and add given css code on it.
Step 3 : Create index.js and add given JavaScript code on it.

HTML


HTML Code for CONVERT DECIMAL NUMBER INTO ROMAN NUMBER


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Roman Number Converter</title>
  <link rel="stylesheet" href="style.css">
</head>
<body>
    <h1>
        CONVERT DECIMAL NUMBER INTO ROMAN NUMBER
    </h1>
    <div class="container">
      <input type="number" id="decimalNumber" placeholder="Enter a Decimal Number">
      <button onclick="convertToRoman()">Convert</button>
      <div id="result">Enter The Number & Hit Convert</div>
    </div>

    <script src="index.js">
    </script>
</body>
</html>
    


CSS


CSS Code for CONVERT DECIMAL NUMBER INTO ROMAN NUMBER

    
*{
    padding: 0;
    margin: 0;
}
body{
    font-family: Arial, Helvetica, sans-serif;
    margin: 0;
    padding: 20px;
}
h1{
    text-align: center;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: lighter;
    margin: 40px;
}
.container{
    box-shadow: 7px 8px 25px rgba(0,0,0,0.301);
    padding: 20px;
    max-width: 500px;
    margin: 0 auto;
    border-radius: 10px;
}
input[type="number"] {
    outline: none;
    width: 400px;
    padding: 10px;
    margin-bottom: 10px;
    font-size: 16px;
    box-sizing: border-box;
}
button{
    width: 90px;
    padding: 11px;
    border-radius: 5px;
    cursor: pointer;
    background: #0099ffe0;
    color: white;
    font-size: 16px;
    border: none;
}
button:hover{
    background-color: #0091ff;
}
#result{
    margin-top: 10px;
    width: auto;
    height: auto;
    background: none;
    padding: 10px;
    text-align: center;
}
    


JavaScript


JavaScript code for CONVERT DECIMAL NUMBER INTO ROMAN NUMBER

            
        function convertToRoman() {
          var decimalNumber = parseInt(document.getElementById("decimalNumber").value);
          if(isNaN(decimalNumber)) {
            alert("please enter a vaild number.");
            return;
          }

          var romanNumeral = "";
          var romanNumerals = ["M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I"];
          var decimalValues = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];

          for (var i = 0; i < decimalValues.length; i++) {
            while (decimalNumber >= decimalValues[i]) {
              romanNumeral += romanNumerals[i];
              decimalNumber -= decimalValues[i];
            }
          }

          document.getElementById("result").innerHTML = "" + romanNumeral;

        }
    






What is HTML

HTML, or HyperText Markup Language, is the standard markup language used to create and design documents on the World Wide Web. It's essentially the backbone of web pages, providing the structure and content that web browsers interpret and display.

HTML consists of a series of elements, which are enclosed by tags to define their purpose and function on a webpage. These elements can include headings, paragraphs, images, links, lists, forms, and more. By using a combination of HTML elements, web developers can organize and present information in a structured and visually appealing manner.

HTML is not a programming language but rather a markup language. This means it doesn't have the capability to perform calculations or execute complex logic like programming languages do. Instead, HTML focuses on describing the structure and content of a document, leaving the presentation and functionality to other technologies like CSS (Cascading Style Sheets) for styling and JavaScript for interactivity.

In summary, HTML serves as the foundation for building web pages, providing the structure and content necessary for browsers to render and display information to users on the internet.

What is CSS

CSS, or Cascading Style Sheets, is a language used to style the presentation of web documents written in HTML and XML. It provides a way to control the layout, colors, fonts, and other visual aspects of a webpage, enabling developers to create attractive and responsive designs. By separating content from presentation, CSS promotes cleaner code, easier maintenance, and greater flexibility in website design. With CSS, developers can achieve consistent branding, improved user experience, and better accessibility across various devices and screen sizes.

What is JavaScript

JavaScript is a versatile programming language used for creating dynamic and interactive web content. It enables developers to manipulate HTML elements, respond to user actions, and build seamless web applications. With its extensive ecosystem of libraries and frameworks, JavaScript powers both client-side and server-side development, making it an essential tool for modern web development.