-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
106 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,18 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<title>Number to French Converter</title> | ||
<link rel="stylesheet" href="styles.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<h1>Number to French Converter</h1> | ||
<input type="text" id="numberInput" placeholder="Enter a number"> | ||
<button onclick="convertToFrench()">Convert</button> | ||
<p id="result"></p> | ||
</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,53 @@ | ||
function convertToFrench() { | ||
const numberInput = document.getElementById('numberInput').value; | ||
let number; | ||
|
||
try { | ||
number = BigInt(numberInput); | ||
} catch (e) { | ||
document.getElementById('result').textContent = 'Please enter a valid number.'; | ||
return; | ||
} | ||
|
||
const resultElement = document.getElementById('result'); | ||
const frenchWords = convertNumberToFrench(number); | ||
resultElement.textContent = `French: ${frenchWords}`; | ||
} | ||
|
||
function convertNumberToFrench(number) { | ||
const units = ['zéro', 'un', 'deux', 'trois', 'quatre', 'cinq', 'six', 'sept', 'huit', 'neuf']; | ||
const teens = ['dix', 'onze', 'douze', 'treize', 'quatorze', 'quinze', 'seize', 'dix-sept', 'dix-huit', 'dix-neuf']; | ||
const tens = ['', 'dix', 'vingt', 'trente', 'quarante', 'cinquante', 'soixante', 'soixante', 'quatre-vingt', 'quatre-vingt']; | ||
const specialTens = ['soixante-dix', 'quatre-vingt-dix']; | ||
|
||
if (number === 0n) return units[0]; | ||
|
||
let result = ''; | ||
let numStr = number.toString(); | ||
|
||
if (numStr.length > 3) { | ||
result += convertNumberToFrench(BigInt(numStr.slice(0, -3))) + ' mille '; | ||
numStr = numStr.slice(-3); | ||
} | ||
|
||
if (numStr.length === 3) { | ||
if (numStr[0] !== '0') { | ||
result += units[Number(numStr[0])] + ' cent '; | ||
} | ||
numStr = numStr.slice(1); | ||
} | ||
|
||
if (numStr.length === 2) { | ||
if (numStr[0] === '1') { | ||
result += teens[Number(numStr[1])] + ' '; | ||
} else if (numStr[0] === '7' || numStr[0] === '9') { | ||
result += specialTens[Number(numStr[0]) - 7] + '-' + units[Number(numStr[1])] + ' '; | ||
} else { | ||
result += tens[Number(numStr[0])] + ' ' + units[Number(numStr[1])] + ' '; | ||
} | ||
} else if (numStr.length === 1) { | ||
result += units[Number(numStr[0])] + ' '; | ||
} | ||
|
||
return result.trim(); | ||
} |
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,35 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
height: 100vh; | ||
margin: 0; | ||
background-color: #f0f0f0; | ||
} | ||
|
||
.container { | ||
text-align: center; | ||
background-color: #fff; | ||
padding: 20px; | ||
border-radius: 8px; | ||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); | ||
} | ||
|
||
input { | ||
padding: 10px; | ||
margin: 10px; | ||
font-size: 16px; | ||
} | ||
|
||
button { | ||
padding: 10px 20px; | ||
font-size: 16px; | ||
cursor: pointer; | ||
} | ||
|
||
p { | ||
margin-top: 20px; | ||
font-size: 18px; | ||
color: #333; | ||
} |