Optimizing stuff
This commit is contained in:
parent
108295322f
commit
d7fa494ffc
@ -10,7 +10,7 @@ Le projet est disponible sur [function.divlo.fr](https://function.divlo.fr/).
|
||||
|
||||
[Projet uniquement en français]
|
||||
|
||||
[![FunctionProject](https://cloud.divlo.fr/public_files/others/FunctionProject/FunctionProject.png)](https://function.divlo.fr/)
|
||||
[![FunctionProject](/img/FunctionProject.png)](https://function.divlo.fr/)
|
||||
|
||||
## La liste des Fonctions Principales :
|
||||
| Nom | Description | Paramètre(s) |
|
||||
|
@ -22,15 +22,14 @@ function weatherRequest() {
|
||||
|
||||
// Génère un nombre aléatoire entre un minimum inclus et un maximum inclus
|
||||
function randomNumber(min, max) {
|
||||
if (!isNaN(min) && !isNaN(max))
|
||||
{
|
||||
min = Math.ceil(min);
|
||||
max = Math.floor(max);
|
||||
|
||||
if (!isNaN(min) && !isNaN(max) && min < max)
|
||||
{
|
||||
return Math.floor(Math.random() * (max - min +1)) + min;
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
return messageError;
|
||||
}
|
||||
}
|
||||
|
||||
@ -158,64 +157,28 @@ function getRandomQuote() {
|
||||
|
||||
// Convertis une valeur dans une devise dans une autre devise
|
||||
function convertCurrency(value, currency, url) {
|
||||
function currencyTest(currencyToTest) {
|
||||
for (let index in correspondancesMonnaie) {
|
||||
if(currencyToTest === correspondancesMonnaie[index]['currency']) {
|
||||
return correspondancesMonnaie[index]['symbol'];
|
||||
}
|
||||
continue;
|
||||
}
|
||||
}
|
||||
$.ajax({
|
||||
url : url,
|
||||
dataType : "json",
|
||||
success: function (jsonFixer) {
|
||||
switch(currency) {
|
||||
case '£':
|
||||
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.GBP) * value)).toFixed(2) + ' ' + currency);
|
||||
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
|
||||
break;
|
||||
case '$ Américain':
|
||||
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.USD) * value)).toFixed(2) + ' ' + currency);
|
||||
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
|
||||
break;
|
||||
case '$ Canadien':
|
||||
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.CAD) * value)).toFixed(2) + ' ' + currency);
|
||||
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
|
||||
break;
|
||||
case '$ Australien':
|
||||
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.AUD) * value)).toFixed(2) + ' ' + currency);
|
||||
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
|
||||
break;
|
||||
case '$ Mexicain':
|
||||
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.MXN) * value)).toFixed(2) + ' ' + currency);
|
||||
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
|
||||
break;
|
||||
case 'CHF':
|
||||
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.CHF) * value)).toFixed(2) + ' ' + currency);
|
||||
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
|
||||
break;
|
||||
case '₽':
|
||||
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.RUB) * value)).toFixed(2) + ' ' + currency);
|
||||
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
|
||||
break;
|
||||
case 'R$':
|
||||
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.BRL) * value)).toFixed(2) + ' ' + currency);
|
||||
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
|
||||
break;
|
||||
case '¥':
|
||||
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(jsonFixer.rates.JPY) * value)).toFixed(2) + ' ' + currency);
|
||||
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
|
||||
break;
|
||||
case '€':
|
||||
let rateEUR = jsonFixer.rates.EUR;
|
||||
if (isNaN(rateEUR)) {
|
||||
$('.results').html(formatNumberResult(value) + ' €');
|
||||
} else {
|
||||
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + ((parseFloat(rateEUR) * value)).toFixed(2) + ' ' + currency);
|
||||
try {
|
||||
let currencySymboleAPI = eval(`jsonFixer.rates.${currencyTest(currency)}`);
|
||||
if (currencySymboleAPI === undefined) {
|
||||
currencySymboleAPI = 1;
|
||||
}
|
||||
$('.results').html(formatNumberResult(value) + ' ' + jsonFixer.base + ' = ' + (currencySymboleAPI * value).toFixed(2) + ' ' + currency);
|
||||
$('.rateDate').html("Dernier rafraîchissement du taux d'échange : " + jsonFixer.date);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
$('.results').html(formatNumberResult(value) + ' €');
|
||||
break;
|
||||
}
|
||||
},
|
||||
statusCode: {
|
||||
404: function() {
|
||||
document.location.replace("../404.php");
|
||||
catch (error) {
|
||||
$('.results').html(messageError);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -26,16 +26,13 @@ $(function () {
|
||||
{
|
||||
$('.results').html(emptyMessageError);
|
||||
}
|
||||
else if (!isNaN(parseInt(minEntered)) && !isNaN(parseInt(maxEntered)))
|
||||
{
|
||||
let result = randomNumber(minEntered, maxEntered);
|
||||
if (minEntered < maxEntered)
|
||||
{
|
||||
$('.results').html("Nombre aléatoire compris entre " + minEntered + " inclus et " + maxEntered + " inclus : " + formatNumberResult(result));
|
||||
}
|
||||
else
|
||||
{
|
||||
let result = randomNumber(minEntered, maxEntered);
|
||||
if(result === messageError) {
|
||||
$('.results').html(messageError);
|
||||
} else {
|
||||
$('.results').html("Nombre aléatoire compris entre " + minEntered + " inclus et " + maxEntered + " inclus : " + formatNumberResult(result));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -11,6 +11,51 @@ let timeNow = new Date();
|
||||
let utcOffset = timeNow.getTimezoneOffset();
|
||||
timeNow.setMinutes(timeNow.getMinutes() + utcOffset);
|
||||
|
||||
// Variable pour convertCurrency
|
||||
const correspondancesMonnaie =
|
||||
[
|
||||
{
|
||||
currency:"£",
|
||||
symbol:"GBP"
|
||||
},
|
||||
{
|
||||
currency: "$ Américain",
|
||||
symbol: "USD"
|
||||
},
|
||||
{
|
||||
currency: "$ Canadien",
|
||||
symbol: "CAD"
|
||||
},
|
||||
{
|
||||
currency: "$ Australien",
|
||||
symbol: "AUD"
|
||||
},
|
||||
{
|
||||
currency: "$ Mexicain",
|
||||
symbol: "MXN"
|
||||
},
|
||||
{
|
||||
currency: "CHF",
|
||||
symbol: "CHF"
|
||||
},
|
||||
{
|
||||
currency: "₽",
|
||||
symbol: "RUB"
|
||||
},
|
||||
{
|
||||
currency: "R$",
|
||||
symbol: "BRL"
|
||||
},
|
||||
{
|
||||
currency: "¥",
|
||||
symbol: "JPY"
|
||||
},
|
||||
{
|
||||
currency: "€",
|
||||
symbol: "EUR"
|
||||
},
|
||||
];
|
||||
|
||||
// Variable pour randomQuote
|
||||
const quotes =
|
||||
[
|
||||
@ -63,7 +108,7 @@ const quotes =
|
||||
source:"Pythagore"
|
||||
},
|
||||
{
|
||||
quote:"Le travail acharné bat le talent quand le talent ne travaille pas dur.",
|
||||
quote:"Le travail acharné bat le talent quand le talent ne travaille pas.",
|
||||
source:"Tim Notke"
|
||||
},
|
||||
{
|
||||
|
@ -13,7 +13,7 @@
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="numberToTest">Entrez votre nombre :</label>
|
||||
<textarea name="numberToTest" type="text" id="numberToTest" placeholder="(e.g : 153)" class="form-control"></textarea>
|
||||
<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">
|
||||
|
Reference in New Issue
Block a user