From aab3aade89a7730ac118ed75c8a03a8d6eed98fc Mon Sep 17 00:00:00 2001 From: Ken Kahn Date: Fri, 2 Aug 2024 15:07:11 +0100 Subject: [PATCH] number to french by mistral large 2 --- .../index.html | 18 +++++++ .../script.js | 53 +++++++++++++++++++ .../styles.css | 35 ++++++++++++ 3 files changed, 106 insertions(+) create mode 100644 apps/number to french by Mistral Large 2/index.html create mode 100644 apps/number to french by Mistral Large 2/script.js create mode 100644 apps/number to french by Mistral Large 2/styles.css diff --git a/apps/number to french by Mistral Large 2/index.html b/apps/number to french by Mistral Large 2/index.html new file mode 100644 index 0000000..14918ee --- /dev/null +++ b/apps/number to french by Mistral Large 2/index.html @@ -0,0 +1,18 @@ + + + + + + Number to French Converter + + + +
+

Number to French Converter

+ + +

+
+ + + \ No newline at end of file diff --git a/apps/number to french by Mistral Large 2/script.js b/apps/number to french by Mistral Large 2/script.js new file mode 100644 index 0000000..24db741 --- /dev/null +++ b/apps/number to french by Mistral Large 2/script.js @@ -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(); +} diff --git a/apps/number to french by Mistral Large 2/styles.css b/apps/number to french by Mistral Large 2/styles.css new file mode 100644 index 0000000..b816eae --- /dev/null +++ b/apps/number to french by Mistral Large 2/styles.css @@ -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; +} \ No newline at end of file