Small hotfix on convertRomanToArabic and contrary

This commit is contained in:
Divlo 2019-10-06 21:03:50 +02:00
parent 7b66463c73
commit 3780269dd3
3 changed files with 18 additions and 5 deletions

View File

@ -8,7 +8,7 @@
<div class="container"> <div class="container">
<div class="row pb-5"> <div class="row pb-5">
<h1>Bienvenue sur <span class="important">FunctionProject</span> <i class="fas fa-file-code"></i></h1> <h1>Bienvenue sur <span class="important">FunctionProject</span> <i class="fas fa-file-code"></i></h1>
<p class="pt-4 mx-auto"><a href="./views/function-list.php">Liste de Mini-programme</a> permettant de <b>savoir la météo</b>, générer un <b>nombre aléatoire</b>, etc.</p> <p class="pt-4 mx-auto"><a href="/views/function-list.php">Liste de Mini-programme</a> permettant de <a href="/views/function-views/weatherRequest.php">savoir la météo</a>, générer un <a href="/views/function-views/randomNumber.php">nombre aléatoire</a>, etc.</p>
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-12 col-md-6 pb-4"> <div class="col-sm-12 col-md-6 pb-4">

View File

@ -338,7 +338,11 @@ function convertArabicToRoman(nombre) {
extraireChiffreRomain(correspondance[0], correspondance[1]); extraireChiffreRomain(correspondance[0], correspondance[1]);
}) })
return chiffresRomains; if (chiffresRomains === '') {
return messageError;
} else {
return chiffresRomains;
}
} }
// Convertis un nombre romain en nombre arabe // Convertis un nombre romain en nombre arabe

View File

@ -224,8 +224,13 @@ $(function () {
$('.results').html(emptyMessageError); $('.results').html(emptyMessageError);
} }
else if (!isNaN(parseInt(numbersValue)) && convertNumberType === "Nombre Romain") { else if (!isNaN(parseInt(numbersValue)) && convertNumberType === "Nombre Romain") {
let result = convertArabicToRoman(parseInt(numbersValue.replace(/\s/g,''))); let result = convertArabicToRoman(parseInt(numbersValue.replace(/\s/g,'')));
$('.results').html(`<b>${formatNumberResult(numbersValue.replace(/\s/g,''))}</b> s'écrit <b>${result}</b> en chiffres romains.`); let numbersValueFormat = formatNumberResult(numbersValue.replace(/\s/g,''));
if (numbersValueFormat === messageError || result === messageError) {
$('.results').html(messageError);
} else {
$('.results').html(`<b>${numbersValueFormat}</b> s'écrit <b>${result}</b> en chiffres romains.`);
}
} }
else if (convertNumberType === "Nombre Arabe") { else if (convertNumberType === "Nombre Arabe") {
if (!isNaN(parseInt(numbersValue))) { if (!isNaN(parseInt(numbersValue))) {
@ -233,7 +238,11 @@ $(function () {
} else { } else {
numbersValue = numbersValue.toUpperCase(); numbersValue = numbersValue.toUpperCase();
let result = convertRomanToArabic(numbersValue); let result = convertRomanToArabic(numbersValue);
$('.results').html(`<b>${numbersValue}</b> s'écrit <b>${result}</b> en chiffres arabes.`); if (result === 0) {
$('.results').html(messageError);
} else {
$('.results').html(`<b>${numbersValue}</b> s'écrit <b>${result}</b> en chiffres arabes.`);
}
} }
} }
else { else {