Remove useless submit and variable RomanToArabic

This commit is contained in:
Divlo 2019-10-11 19:08:28 +02:00
parent 0b0544d783
commit 23c3e10b0f
5 changed files with 39 additions and 66 deletions

View File

@ -62,6 +62,7 @@ function calculateAge(birthDateEntered) {
// Vérifie si la valeur entrée correspond à une date de naissance valide // Vérifie si la valeur entrée correspond à une date de naissance valide
if(isValidDateFunction === true) if(isValidDateFunction === true)
{ {
ageYears = formatNumberResult(ageYears);
// Si c'est ton anniversaire aujourd'hui // Si c'est ton anniversaire aujourd'hui
if(birthDateDay === parseInt(day) && (parseInt(birthDateMonth) + 1) === parseInt(month)) if(birthDateDay === parseInt(day) && (parseInt(birthDateMonth) + 1) === parseInt(month))
{ {
@ -254,7 +255,7 @@ function convertDecimalBinaryHexadecimal(value, option) {
} }
} }
else if (option === 'BinaryToDecimal') { else if (option === 'BinaryToDecimal') {
return parseInt(value, 2); return formatNumberResult(parseInt(value, 2));
} }
else if (option === 'DecimalToHexadecimal') { else if (option === 'DecimalToHexadecimal') {
value = value.replace(" ", ""); value = value.replace(" ", "");
@ -266,7 +267,7 @@ function convertDecimalBinaryHexadecimal(value, option) {
} }
} }
else if (option === 'HexadecimalToDecimal') { else if (option === 'HexadecimalToDecimal') {
return parseInt(value, 16); return formatNumberResult(parseInt(value, 16));
} }
else if (option === 'BinaryToHexadecimal') { else if (option === 'BinaryToHexadecimal') {
value = parseInt(value, 2); value = parseInt(value, 2);
@ -295,24 +296,6 @@ function convertDecimalBinaryHexadecimal(value, option) {
// Convertis un nombre arabe en nombre romain // Convertis un nombre arabe en nombre romain
function convertArabicToRoman(nombre) { function convertArabicToRoman(nombre) {
// Tableau contenant chaque correspondance entre un nombre arabe et un nombre romain
const correspondances =
[
[1000, "M"],
[900, "CM"],
[500, "D"],
[400, "CD"],
[100, "C"],
[90, "XC"],
[50, "L"],
[40, "XL"],
[10, "X"],
[9, "IX"],
[5, "V"],
[4, "IV"],
[1, "I"],
];
// Initialisation de la variable qui va contenir le résultat de la conversion // Initialisation de la variable qui va contenir le résultat de la conversion
let chiffresRomains = ""; let chiffresRomains = "";
@ -337,7 +320,7 @@ function convertArabicToRoman(nombre) {
} }
} }
correspondances.forEach(correspondance => { correspondancesRomainArabe.forEach(correspondance => {
extraireChiffreRomain(correspondance[0], correspondance[1]); extraireChiffreRomain(correspondance[0], correspondance[1]);
}) })
@ -350,17 +333,13 @@ function convertArabicToRoman(nombre) {
// Convertis un nombre romain en nombre arabe // Convertis un nombre romain en nombre arabe
function convertRomanToArabic(str) { function convertRomanToArabic(str) {
var result = 0; let result = 0;
// the result is now a number, not a string for (let i = 0;i < correspondancesRomainArabe.length; i++) {
var decimal = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1]; while (str.indexOf(correspondancesRomainArabe[i][1]) === 0){
var roman = ["M", "CM","D","CD","C", "XC", "L", "XL", "X","IX","V","IV","I"]; // Adding the decimal value to our result counter
for (var i = 0;i<=decimal.length;i++) { result += correspondancesRomainArabe[i][0];
while (str.indexOf(roman[i]) === 0){ // Remove the matched Roman letter from the beginning
//checking for the first characters in the string str = str.replace(correspondancesRomainArabe[i][1],'');
result += decimal[i];
//adding the decimal value to our result counter
str = str.replace(roman[i],'');
//remove the matched Roman letter from the beginning
} }
} }
if (str != '') { if (str != '') {
@ -381,9 +360,10 @@ function armstrongNumber(number) {
resultString = resultString + " + " + numberString[i] + "<sup>" + numberStringLength + "</sup>"; resultString = resultString + " + " + numberString[i] + "<sup>" + numberStringLength + "</sup>";
} }
number = formatNumberResult(number);
if (result === number) { if (result === number) {
return `${formatNumberResult(number)} est un nombre d'Armstrong, car ${resultString.slice(2)} = ${formatNumberResult(result)}.`; return `${number} est un nombre d'Armstrong, car ${resultString.slice(2)} = ${formatNumberResult(result)}.`;
} else { } else {
return `${formatNumberResult(number)} n'est pas un nombre d'Armstrong, car ${resultString.slice(2)} = ${formatNumberResult(result)}.`; return `${number} n'est pas un nombre d'Armstrong, car ${resultString.slice(2)} = ${formatNumberResult(result)}.`;
} }
} }

View File

@ -37,16 +37,9 @@ $(function () {
} }
}); });
$("#submitCalculateAge").click(function() $("#birthDateValue").bind("keyup change", function()
{ {
let birthDateEntered = $('#birthDateValue').val(); let birthDateEntered = $('#birthDateValue').val();
if(isEmptyValue(birthDateEntered))
{
$('.results').html(emptyMessageError);
}
else
{
let result = calculateAge(birthDateEntered); let result = calculateAge(birthDateEntered);
if(result === messageError) if(result === messageError)
{ {
@ -56,7 +49,6 @@ $(function () {
{ {
$('.results').html(result); $('.results').html(result);
} }
}
}); });
$("#submitConvertTemperature").click(function() $("#submitConvertTemperature").click(function()
@ -250,14 +242,10 @@ $(function () {
} }
}); });
$("#submitArmstrongNumber").click(function() $("#numberToTest").bind("keyup change", function()
{ {
let numbersValue = $('#numberToTest').val(); let numbersValue = $('#numberToTest').val();
if (!isNaN(parseInt(numbersValue))) {
if(isEmptyValue(numbersValue)) {
$('.results').html(emptyMessageError);
}
else if (!isNaN(parseInt(numbersValue))) {
let result = armstrongNumber(parseFloat(numbersValue.replace(/\s/g,''))); let result = armstrongNumber(parseFloat(numbersValue.replace(/\s/g,'')));
$('.results').html(result); $('.results').html(result);
} }

View File

@ -11,6 +11,24 @@ let timeNow = new Date();
let utcOffset = timeNow.getTimezoneOffset(); let utcOffset = timeNow.getTimezoneOffset();
timeNow.setMinutes(timeNow.getMinutes() + utcOffset); timeNow.setMinutes(timeNow.getMinutes() + utcOffset);
// Variable pour convertRomanArabicNumbers
const correspondancesRomainArabe =
[
[1000, "M"],
[900, "CM"],
[500, "D"],
[400, "CD"],
[100, "C"],
[90, "XC"],
[50, "L"],
[40, "XL"],
[10, "X"],
[9, "IX"],
[5, "V"],
[4, "IV"],
[1, "I"],
];
// Variable pour convertCurrency // Variable pour convertCurrency
const correspondancesMonnaie = const correspondancesMonnaie =
[ [

View File

@ -14,13 +14,6 @@
<div class="form-group"> <div class="form-group">
<label for="numberToTest">Entrez votre nombre :</label> <label for="numberToTest">Entrez votre nombre :</label>
<input name="numberToTest" type="number" id="numberToTest" placeholder="(e.g : 153)" class="form-control"> <input name="numberToTest" type="number" id="numberToTest" placeholder="(e.g : 153)" class="form-control">
<br>
<div class="form-row text-center">
<div class="col-12">
<br>
<button type="submit" id="submitArmstrongNumber" class="btn btn-dark text-center">Envoyer</button>
</div>
</div>
<br> <br> <br> <br>
<p class="results text-center"></p> <p class="results text-center"></p>
</div> </div>

View File

@ -14,12 +14,6 @@
<div class="form-group"> <div class="form-group">
<label for="birthDateValue">Entrez la date de naissance au format (dd/mm/yyyy) :</label> <label for="birthDateValue">Entrez la date de naissance au format (dd/mm/yyyy) :</label>
<input name="birthDateValue" type="text" id="birthDateValue" placeholder="Sélectionnez une date" class="form-control datepicker"> <input name="birthDateValue" type="text" id="birthDateValue" placeholder="Sélectionnez une date" class="form-control datepicker">
<br>
<div class="form-row text-center">
<div class="col-12">
<button type="submit" id="submitCalculateAge" class="btn btn-dark text-center">Envoyer</button>
</div>
</div>
<br> <br> <br> <br>
<p class="results text-center"></p> <p class="results text-center"></p>
</div> </div>