Improve the message by changing the hailing
This commit is contained in:
parent
1e1ac0080a
commit
1306259015
4 changed files with 37 additions and 15 deletions
17
src/Hail.js
Normal file
17
src/Hail.js
Normal file
|
@ -0,0 +1,17 @@
|
|||
import Random;
|
||||
|
||||
var greetings = [
|
||||
"Gloire à",
|
||||
"Longue vie à",
|
||||
"Vive"
|
||||
];
|
||||
var latest = null;
|
||||
|
||||
return {
|
||||
hail: hail
|
||||
};
|
||||
|
||||
function hail(name) {
|
||||
latest = Random.element(greetings.filter(function(g) {return g != latest}));
|
||||
return latest + ' ' + name + ' !';
|
||||
}
|
16
src/Main.js
16
src/Main.js
|
@ -1,19 +1,9 @@
|
|||
import Roots;
|
||||
import hail from Hail;
|
||||
import Name;
|
||||
|
||||
var generate = document.getElementById('generate');
|
||||
var result = document.getElementById('result');
|
||||
|
||||
function random(roots) {
|
||||
var i = Math.floor(roots.length * Math.random());
|
||||
return roots[i];
|
||||
}
|
||||
|
||||
function name() {
|
||||
var prefix = random(Roots.prefixes);
|
||||
var suffix = random(Roots.suffixes);
|
||||
return prefix + suffix;
|
||||
}
|
||||
|
||||
generate.addEventListener('click', function() {
|
||||
result.textContent = "Gloire à " + name() + " !";
|
||||
result.textContent = hail(Name.random());
|
||||
});
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
import Random;
|
||||
|
||||
var prefixes = [
|
||||
"Adal",
|
||||
"Aethel",
|
||||
|
@ -51,6 +53,11 @@ var suffixes = [
|
|||
];
|
||||
|
||||
return {
|
||||
prefixes: prefixes,
|
||||
suffixes: suffixes
|
||||
random: random
|
||||
};
|
||||
|
||||
function random() {
|
||||
var prefix = Random.element(prefixes);
|
||||
var suffix = Random.element(suffixes);
|
||||
return prefix + suffix;
|
||||
}
|
8
src/Random.js
Normal file
8
src/Random.js
Normal file
|
@ -0,0 +1,8 @@
|
|||
return {
|
||||
element: element
|
||||
};
|
||||
|
||||
function element(elements) {
|
||||
var i = Math.floor(elements.length * Math.random());
|
||||
return elements[i];
|
||||
}
|
Loading…
Reference in a new issue