Compare commits

...

3 commits

Author SHA1 Message Date
6d1829027b
Add constnium logic 2022-06-23 12:40:21 +02:00
2728126e44
Add input 2022-06-23 12:40:02 +02:00
09994bbbed
Update ESLint rules 2022-06-23 12:39:13 +02:00
4 changed files with 101 additions and 1 deletions

View file

@ -29,7 +29,7 @@
"space-infix-ops": "warn",
"brace-style": "warn",
"comma-spacing": "warn",
"indent": "warn",
"indent": ["warn", { "SwitchCase": 2 }],
"arrow-spacing": "warn"
}
}

View file

@ -0,0 +1,4 @@
.form-control {
width: 50% !important;
text-align: center;
}

91
public/js/main.js Normal file
View file

@ -0,0 +1,91 @@
window.addEventListener("load", () => main());
const input_name = "firstname";
const main = () => {
// Reset content of the input
document.getElementById(input_name).value = "";
// Call callback when editing the input
document.getElementById(input_name).addEventListener("input", update_const);
};
// Callback: called when firstname is changed
const update_const = () => {
const firstname = document.getElementById(input_name).value;
const firstname_const = get_const(firstname.split(''));
console.log(`output: ${firstname_const}`);
};
const get_const = (letters = Array) => {
console.log(`input: ${letters}`);
// Store constants of each letters of the firstname
let const_data = [];
// Store some constants info
//let const_infos = {};
// Assign each letter to a const, fallback to 1 if no one has been found
switch (letters) {
/* case 'a':
const_data.push(); */
/* case 'b':
const_data.push(); */
/* case 'c':
const_data.push(); */
/* case 'd':
const_data.push(); */
/* case 'e':
const_data.push(); */
/* case 'f':
const_data.push(); */
/* case 'g':
const_data.push(); */
/* case 'h':
const_data.push(); */
/* case 'i':
const_data.push(); */
/* case 'j':
const_data.push(); */
/* case 'k':
const_data.push(); */
/* case 'l':
const_data.push(); */
/* case 'm':
const_data.push(); */
/* case 'n':
const_data.push(); */
/* case 'o':
const_data.push(); */
/* case 'p':
const_data.push(); */
/* case 'q':
const_data.push(); */
/* case 'r':
const_data.push(); */
/* case 's':
const_data.push(); */
/* case 't':
const_data.push(); */
/* case 'u':
const_data.push(); */
/* case 'v':
const_data.push(); */
/* case 'w':
const_data.push(); */
/* case 'x':
const_data.push(); */
/* case 'y':
const_data.push(); */
/* case 'z':
const_data.push(); */
default:
const_data.push(1);
}
// Multiply all the constants together
return const_data.reduce((a, b) => a * b);
};

View file

@ -26,9 +26,14 @@
</head>
<body>
<img src="images/logo.webp" class="img-fluid mx-auto d-block" alt="Banner">
<input id="firstname" class="form-control form-control-lg mx-auto d-block" type="text" placeholder="Maria">
<hr>
<figure class="text-center">
<%- readme %>
</figure>
<script src="js/main.js"></script>
</body>
</html>