-
Notifications
You must be signed in to change notification settings - Fork 399
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Roman Numeral Calculator (#855)
- Loading branch information
1 parent
317b02f
commit 74a54f0
Showing
5 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# <p align="center">Roman Numeral Calculator</p> | ||
|
||
## Description :- | ||
|
||
Calculator which takes the value in Roman numeral form and gives the results in decimal format. | ||
This calculator only works within the specified range of standard Roman numeral form i.e. within the range 1 to 3999. | ||
|
||
## Tech Stacks :- | ||
|
||
- HTML | ||
- CSS | ||
- JavaScript | ||
|
||
## Screenshots :- | ||
|
||
![image](https://github.com/Rakesh9100/CalcDiverse/assets/73993775/3328c033-55ca-42a8-866e-60afbbc151cd) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<link rel="stylesheet" href="./style.css"> | ||
<title>Roman Numeral Calculator</title> | ||
</head> | ||
|
||
<body> | ||
<div class="converter"> | ||
<h1>Roman Numeral Calculator</h1> | ||
<label for="romanNumeral">Enter Roman Numeral following the standard rules of Roman numeral notation:</label> | ||
<input type="text" id="romanNumeral" placeholder="e.g., XIV"> | ||
<button onclick="convertRomanToDecimal()">Convert</button> | ||
<div id="result"></div> | ||
</div> | ||
<script src="./script.js"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
function convertRomanToDecimal() { | ||
const roman = document.getElementById('romanNumeral').value.toUpperCase(); | ||
const romanToDecimalMap = { | ||
'I': 1, | ||
'V': 5, | ||
'X': 10, | ||
'L': 50, | ||
'C': 100, | ||
'D': 500, | ||
'M': 1000 | ||
}; | ||
|
||
let decimal = 0; | ||
let prevValue = 0; | ||
|
||
for (let i = roman.length - 1; i >= 0; i--) { | ||
const currentValue = romanToDecimalMap[roman[i]]; | ||
if (!currentValue) { | ||
document.getElementById('result').innerText = "Invalid Roman Numeral"; | ||
return; | ||
} | ||
|
||
if (currentValue < prevValue) { | ||
decimal -= currentValue; | ||
} else { | ||
decimal += currentValue; | ||
} | ||
prevValue = currentValue; | ||
} | ||
|
||
document.getElementById('result').innerText = `Decimal: ${decimal}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
background: linear-gradient(to right, #da6854,#ee3405); | ||
} | ||
|
||
.converter { | ||
background-color: white; | ||
padding: 20px; | ||
border-radius: 10px; | ||
box-shadow: 0 0 10px rgba(0,0,0,0.1); | ||
width: 300px; | ||
} | ||
|
||
h1 { | ||
text-align: center; | ||
} | ||
|
||
label { | ||
display: block; | ||
margin: 10px 0 5px; | ||
} | ||
|
||
input { | ||
width: 94%; | ||
padding: 8px; | ||
margin-bottom: 10px; | ||
border: 1px solid #ddd; | ||
border-radius: 5px; | ||
} | ||
|
||
button { | ||
width: 100%; | ||
padding: 10px; | ||
background-color: #c73d07; | ||
color: white; | ||
border: none; | ||
border-radius: 5px; | ||
cursor: pointer; | ||
} | ||
|
||
button:hover { | ||
background-color: #d4804f; | ||
} | ||
|
||
#result { | ||
margin-top: 20px; | ||
text-align: center; | ||
font-size: 1.2em; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters