New function : randomQuote

This commit is contained in:
Divlo
2019-09-13 14:39:29 +02:00
parent 0f50225d13
commit 153da05391
8 changed files with 92 additions and 16 deletions

View File

@ -50,16 +50,10 @@ function randomNumber(min, max) {
if (!isNaN(min) && !isNaN(max) && min < max)
{
let randomNumber = Math.floor(Math.random() * (max - min +1)) + min;
return "Nombre aléatoire compris entre " + min + " inclus et " + max + " inclus : " + randomNumber;
return Math.floor(Math.random() * (max - min +1)) + min;
}
else if (min > max)
{
return "Votre nombre minimum est plus grand que le nombre maximum.";
}
else
{
return messageError;
else {
return null;
}
}
@ -176,6 +170,13 @@ function filterStudents(filteredLetter, students)
}
}
// Génère aléatoirement une citation ou un proverbe.
function getRandomQuote() {
let randomNbr = randomNumber(0, (quotes.length - 1));
let randomQuotes = quotes[randomNbr];
return '" ' + randomQuotes["quote"] + ' " <br> <br> - ' + randomQuotes["source"];
}
/////////////////////////////////////////////////////////////////
/* Fonctions Annexes */

View File

@ -35,17 +35,20 @@ $(function () {
{
$('.results').html(emptyMessageError);
}
else
else if (!isNaN(parseInt(minEntered)) && !isNaN(parseInt(maxEntered)))
{
let result = randomNumber(minEntered, maxEntered);
if(result === messageError)
if (minEntered < maxEntered)
{
$('.results').html(messageError);
$('.results').html("Nombre aléatoire compris entre " + minEntered + " inclus et " + maxEntered + " inclus : " + formatNumberResult(result));
}
else
{
$('.results').html(result);
else if (minEntered > maxEntered) {
$('.results').html("Votre nombre minimum est plus grand que le nombre maximum.");
}
else
{
$('.results').html(messageError);
}
}
});
@ -140,6 +143,17 @@ $(function () {
}
});
let randomQuoteClicked;
$("#submitRandomQuote").click(function()
{
randomQuoteClicked = true;
$('.resultsRandomQuote').html(getRandomQuote());
});
// Affichage d'une citation au chargement de la page
if (randomQuoteClicked != true && window.location.href.indexOf("randomQuote") > -1) {
$('.resultsRandomQuote').html(getRandomQuote());
}
/* Permet d'afficher l'heure en temps réel sur le footer */
window.onload = realDateTime('realDateTime');

View File

@ -7,4 +7,28 @@ const messageError = "Vous n'avez pas rentré de valeur valide.";
/* Varibales pour les fonctions */
let timeNow = new Date();
let utcOffset = timeNow.getTimezoneOffset();
timeNow.setMinutes(timeNow.getMinutes() + utcOffset);
timeNow.setMinutes(timeNow.getMinutes() + utcOffset);
// Variable pour randomQuote
const quotes = [
{
quote: "Two things are infinite: the universe and human stupidity; and I'm not sure about the universe.",
source: "Albert Einstein"
},
{
quote:"Be the change that you wish to see in the world.",
source: "Mahatma Gandhi"
},
{
quote:"Vote for the man who promise least, he'll be the least disappointing.",
source:"Bernard Baruch"
},
{
quote:"Hard work beats talent when talent doesn't work hard.",
source:"Tim Notke"
},
{
quote:"You want to wake up in the morning and think the future is going to be great - and that's what being a spacefaring civilization is all about. It's about believing in the future and thinking that the future will be better than the past. And I can't think of anything more exciting than going out there and being among the stars",
source:"Elon Musk, SpaceX"
}
];